//
//  StockTableQuote.m
//  iStock Global
//
//  Created by Andy on 2010/10/2.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//
//#import "NSDictionary+APFinancalData.h"
#import "StockTableQuote.h"
#import "tablecellgradent.h"
#import "StockTableQuoteCell.h"
#import "CustomUIActionSheetViewControllerNxib.h"
#import "DownloadData.h"
#import "DateFormatter.h"
#import "editWatchList.h"
#import "UIButton+Glossy.h"
#import "AppDelegate.h"
#import <MediaPlayer/MediaPlayer.h>
#import "JSON.h"


#define PROGRESS_BAR	999
#define PROGRESS_LABEL	998
#define  max_download 100 //yahoo 可以一次下載最大數

@implementation StockTableQuote

#pragma mark -
#pragma mark 屬性設定
@synthesize baseSheet;
@synthesize data_code;
@synthesize data_name;
@synthesize data_class;
@synthesize data_id_class;
@synthesize market;
@synthesize delgete;
@synthesize AppleDeglate;
/*
@synthesize overallLow;
@synthesize overallHigh;
@synthesize VoloverallLow;
@synthesize VoloverallHigh;
 */
@synthesize graph;
 

#pragma mark -
#pragma mark 初始化

 
- (id)initWithStyle:(UITableViewStyle)style {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if ((self = [super initWithStyle:style])) {
		downhistoryindex=-1;
		
               
        
	}
    return self;
}
 
  
#pragma mark -
#pragma mark 畫面開啓與取的navcontroller物件指標 初始值設定 
 //初始值設定位置
- (void)viewDidLoad {
    
   // select_table_row=-1;
    NSLog(@"viewDidLoad");
    
    //標記:表格內展開出現日內走勢圖 實體化  
    expand_table_code=[[NSMutableArray alloc] init];    //有哪些表格是展開的
    
    //標記:日內走勢圖記憶體宣告實體與消滅 實體
    intraday_data_code=[[NSMutableArray alloc] init]; //暫存日內資料 名稱
    intraday_data=[[NSMutableArray alloc] init]; //暫存日內資料     
    intraday_data_x_time=[[NSMutableArray alloc] init]; //暫存日內資料     
    intraday_graph_x_length=[[NSMutableArray alloc] init];  
    intraday_graph_x_high=[[NSMutableArray alloc] init];    
    intraday_graph_x_low=[[NSMutableArray alloc] init];    
    intraday_graph_volume_high=[[NSMutableArray alloc] init];     
    intraday_graph_volume_low=[[NSMutableArray alloc] init]; 
    intraday_graph_lastdayClose=[[NSMutableArray alloc] init];      
    intraday_graph_selected_left=[[NSMutableArray alloc] init];  
    intraday_graph_selected_right=[[NSMutableArray alloc] init];     
    
    previous_index=-1;//標記: 清除最小股票單位資料物件	(初始化)
	
    //標記:升級功能限制 日內走勢圖關閉    
    //tablecell_high_zoom_out=320; //顯示的高度
    tablecell_high_zoom_out=320;
    
    
    //表格欄位 格式設定
	{
		
		if (picka1==nil) {
			picka1=[[NSMutableArray alloc] init];
			[picka1 addObject:NSLocalizedString(@"Name", @"名稱")];	
			[picka1 addObject:NSLocalizedString(@"Symbol", @"代號")];
			[picka1 addObject:NSLocalizedString(@"Class", @"分類")];
			[picka1 addObject:NSLocalizedString(@"Name\nSymbol",@"代號\n名稱")];		
			[picka1 addObject:NSLocalizedString(@"Symbol\nName\nClass", @"代號\n名稱\n分類")];	
			[picka1 addObject:NSLocalizedString(@"Symbol\nClass", @"代號\n分類")];
			[picka1 addObject:NSLocalizedString(@"Name\nClass" ,@"名稱\n分類")];
		}
		if (picka2==nil) {
			
			picka2=[[NSMutableArray alloc] init];
			[picka2 addObject:NSLocalizedString(@"Price", @"價格")];	
			[picka2 addObject:NSLocalizedString(@"Time", @"時間")];	
			[picka2 addObject:NSLocalizedString(@"Date", @"日期")];	
			[picka2 addObject:NSLocalizedString(@"Price\nTime", @"價格\n時間")];
			[picka2 addObject:NSLocalizedString(@"Price\nDate", @"價格\n日期")];			
			[picka2 addObject:NSLocalizedString(@"Price\nTime\nDate", @"價格\n時間\n日期")];
			
			[picka2 addObject:NSLocalizedString(@"Change", @"漲跌")];	
			[picka2 addObject:NSLocalizedString(@"Change%", @"漲跌福")];	
			[picka2 addObject:NSLocalizedString(@"Change\nChange%", @"漲跌\n漲跌福")];	
			[picka2 addObject:NSLocalizedString(@"Volume", @"成交量")];	
			[picka2 addObject:NSLocalizedString(@"Change%\nVolume", @"漲跌福\n成交量")];				
			[picka2 addObject:NSLocalizedString(@"EPS Current Year", @"今年EPS")];	
			[picka2 addObject:NSLocalizedString(@"PE Next Year", @"次年PE")];
			
			[picka2 addObject:NSLocalizedString(@"5Day Change%", @"5日漲跌幅")];
			[picka2 addObject:NSLocalizedString(@"10Day Change%", @"10日漲跌幅")];			
			[picka2 addObject:NSLocalizedString(@"20Day Change%", @"20日漲跌幅")];
			
			[picka2 addObject:NSLocalizedString(@"60Day Change%", @"60日漲跌幅")];
			[picka2 addObject:NSLocalizedString(@"120Day Change%",@"120日漲跌幅")];			
			[picka2 addObject:NSLocalizedString(@"240Day Change%", @"240日漲跌幅")];			
			
			[picka2 addObject:NSLocalizedString(@"5Day Change%\n10Day Change%\n20Day Change%", @"5日漲跌幅\n10日漲跌幅\n20日漲跌幅")];			
			[picka2 addObject:NSLocalizedString(@"60Day Change%\n120Day Change%\n240Day Change%", @"60日漲跌幅\n120日漲跌幅\n240日漲跌幅")];			
			
			[picka2 addObject:NSLocalizedString(@"Week Change%", @"週漲跌幅")];
			[picka2 addObject:NSLocalizedString(@"Month Change%", @"月漲跌幅")];			
			[picka2 addObject:NSLocalizedString(@"Quarter Change%", @"季漲跌幅")];			
			[picka2 addObject:NSLocalizedString(@"Year Change%", @"年漲跌幅")];			
			
			
			[picka2 addObject:NSLocalizedString(@"Week Change%\nMonth Change%\nQuarter Change%", @"週漲跌幅\n月漲跌幅\n季漲跌幅")];
			[picka2 addObject:NSLocalizedString(@"Month Change%\nQuarter Change%\nYear Change%", @"月漲跌幅\n季漲跌幅\年漲跌幅")];			
			
            //標記:判斷是MESA或LF
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
            NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
            
            if ([DisplayName_array count]>=3) {
                if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
                    //MESA
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_FAMA1", @"MESA_FAMA1")];
                    [picka2 addObject:NSLocalizedString(@"MESA_MAMA1", @"MESA_MAMA1")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_FAMA2", @"MESA_FAMA2")];
                    [picka2 addObject:NSLocalizedString(@"MESA_MAMA2", @"MESA_MAMA2")];				
                    [picka2 addObject:NSLocalizedString(@"MESA_FAMA3", @"MESA_FAMA3")];
                    [picka2 addObject:NSLocalizedString(@"MESA_MAMA3", @"MESA_MAMA3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"Price\nMESA_FAMA1\nMESA_MAMA1", @"價格\nMESA_FAMA1\nMESA_MAMA1")];				
                    [picka2 addObject:NSLocalizedString(@"Price\nMESA_FAMA2\nMESA_MAMA2", @"價格\nMESA_FAMA2\nMESA_MAMA2")];				
                    [picka2 addObject:NSLocalizedString(@"Price\nMESA_FAMA3\nMESA_MAMA3", @"價格\nMESA_FAMA3\nMESA_MAMA3")];				
                    
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal1", @"MESA_訊號1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal2", @"MESA_訊號2")];					
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal3", @"MESA_訊號3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal1\nMESA_Signal2\nMESA_Signal3", @"MESA_訊號1\nMESA_訊號2\nMESA_訊號3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_Action1", @"MESA_動作1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_Action2", @"MESA_動作2")];					
                    [picka2 addObject:NSLocalizedString(@"MESA_Action3", @"MESA_動作3")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_Action1\nMESA_Action2\nMESA_Action3", @"MESA_動作1\nMESA_動作2\nMESA_動作3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal1\nMESA_Action1", @"MESA_訊號1\nMESA_動作1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal2\nMESA_Action2", @"MESA_訊號1\nMESA_動作2")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_Signal3\nMESA_Action3", @"MESA_訊號1\nMESA_動作3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay1", @"MESA_買入天數1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay2", @"MESA_買入天數2")];
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay3", @"MESA_買入天數3")];	
                    
                    
                    
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay1", @"MESA_賣出天數1")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay2", @"MESA_賣出天數2")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay3", @"MESA_賣出天數3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay1\nMESA_LongDay2\nMESA_LongDay3", @"MESA_買入天數1\nMESA_買入天數2\nMESA_買入天數3")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay1\nMESA_ShortgDay2\nMESA_ShortgDay3", @"MESA_賣出天數1\nMESA_賣出天數2\nMESA_賣出天數3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongProfit1", @"MESA_買入獲利率1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongProfit2", @"MESA_買入獲利率2")];
                    [picka2 addObject:NSLocalizedString(@"MESA_LongProfit3", @"MESA_買入獲利率3")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgProfit1", @"MESA_賣出獲利率1")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgProfit2", @"MESA_賣出獲利率2")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgProfit3", @"MESA_賣出獲利率3")];				
                    
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongProfit1\nMESA_LongProfit2\nMESA_LongProfit3", @"MESA_買入獲利率1\nMESA_買入獲利率2\nMESA_買入獲利率3")];				
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgProfit1\nMESA_ShortgProfit2\nMESA_ShortgProfit3", @"MESA_賣出獲利率1\nMESA_賣出獲利率2\nMESA_賣出獲利率3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay1\nMESA_LongProfit1", @"MESA_買入天數1\nMESA_買入獲利率1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay2\nMESA_LongProfit2", @"MESA_買入天數2\nMESA_買入獲利率2")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay3\nMESA_LongProfit3", @"MESA_買入天數3\nMESA_買入獲利率3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay1\nMESA_ShortgProfit1", @"MESA_賣出天數1\nMESA_賣出獲利率1")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay2\nMESA_ShortgProfit2", @"MESA_賣出天數1\nMESA_賣出獲利率2")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay3\nMESA_ShortgProfit3", @"MESA_賣出天數1\nMESA_賣出獲利率3")];				
                    
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay1\nMESA_LongProfit1\nPrice", @"MESA_買入天數1\nMESA_買入獲利率1\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay2\nMESA_LongProfit2\nPrice", @"MESA_買入天數2\nMESA_買入獲利率2\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_LongDay3\nMESA_LongProfit3\nPrice", @"MESA_買入天數3\nMESA_買入獲利率3\n價格")];			
                    
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay1\nMESA_ShortgProfit1\nPrice", @"MESA_賣出天數1\nMESA_賣出獲利率1\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay2\nMESA_ShortgProfit2\nPrice", @"MESA_賣出天數1\nMESA_賣出獲利率2\n價格")];	
                    [picka2 addObject:NSLocalizedString(@"MESA_ShortgDay3\nMESA_ShortgProfit3\nPrice", @"MESA_賣出天數1\nMESA_賣出獲利率3\n價格")];                
                
                }
                else{
                    //開始LF
                    //顯式LF 多空狀態
                    [picka2 addObject:NSLocalizedString(@"LF_Signal1", @"LF_訊號1")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Signal2", @"LF_訊號2")];					
                    [picka2 addObject:NSLocalizedString(@"LF_Signal3", @"LF_訊號3")];	
                    [picka2 addObject:NSLocalizedString(@"LF_Signal1\nLF_Signal2\nLF_Signal3", @"LF_訊號1\nLF_訊號2\nLF_訊號3")];			
                    
                    
                    [picka2 addObject:NSLocalizedString(@"LF_Action1", @"LF_動作1")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Action2", @"LF_動作2")];					
                    [picka2 addObject:NSLocalizedString(@"LF_Action3", @"LF_動作3")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Action1\nLF_Action2\nLF_Action3", @"LF_動作1\nLF_動作2\nLF_動作3")];
                    
                    
                    [picka2 addObject:NSLocalizedString(@"LF_Break P1", @"LF_關鍵價位1")];
                    [picka2 addObject:NSLocalizedString(@"LF_Break P2", @"LF_關鍵價位2")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Break P3", @"LF_關鍵價位3")];			
                    
                    
                    [picka2 addObject:NSLocalizedString(@"LF_Break P1\nLF_Break P2\nLF_Break P3", @"LF_關鍵價位1\nLF_關鍵價位2\nLF_關鍵價位3")];			
                    
                    [picka2 addObject:NSLocalizedString(@"LF_Signal1\nLF_Break P1\nPrice", @"LF_訊號1\nLF_關鍵價位1\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Signal2\nLF_Break P2\nPrice", @"LF_訊號2\nLF_關鍵價位2\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"LF_Signal3\nLF_Break P3\nPrice", @"LF_訊號3\nLF_關鍵價位3\n價格")];			
                    
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay1", @"LF_買入天數1")];			
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay2", @"LF_買入天數2")];
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay3", @"LF_買入天數3")];	
                    
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay1", @"LF_賣出天數1")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay2", @"LF_賣出天數2")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay3", @"LF_賣出天數3")];	
                    
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay1\nLF_LongDay2\nLF_LongDay3", @"LF_買入天數1\nLF_買入天數2\nLF_買入天數3")];			
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay1\nLF_ShortgDay2\nLF_ShortgDay3", @"LF_賣出天數1\nLF_賣出天數2\nLF_賣出天數3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"LF_LongProfit1", @"LF_買入獲利率1")];			
                    [picka2 addObject:NSLocalizedString(@"LF_LongProfit2", @"LF_買入獲利率2")];
                    [picka2 addObject:NSLocalizedString(@"LF_LongProfit3", @"LF_買入獲利率3")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgProfit1", @"LF_賣出獲利率1")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgProfit2", @"LF_賣出獲利率2")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgProfit3", @"LF_賣出獲利率3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"LF_LongProfit1\nLF_LongProfit2\nLF_LongProfit3", @"LF_買入獲利率1\nLF_買入獲利率2\nLF_買入獲利率3")];				
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgProfit1\nLF_ShortgProfit2\nLF_ShortgProfit3", @"LF_賣出獲利率1\nLF_賣出獲利率2\nLF_賣出獲利率3")];				
                    
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay1\nLF_LongProfit1\nPrice", @"LF_買入天數1\nLF_買入獲利率1\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay2\nLF_LongProfit2\nPrice", @"LF_買入天數2\nLF_買入獲利率2\n價格")];			
                    [picka2 addObject:NSLocalizedString(@"LF_LongDay3\nLF_LongProfit3\nPrice", @"LF_買入天數3\nLF_買入獲利率3\n價格")];
                    
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay1\nLF_ShortgProfit1\nPrice", @"LF_賣出天數1\nLF_賣出獲利率1\n價格")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay2\nLF_ShortgProfit2\nPrice", @"LF_賣出天數2\nLF_賣出獲利率2\n價格")];	
                    [picka2 addObject:NSLocalizedString(@"LF_ShortgDay3\nLF_ShortgProfit3\nPrice", @"LF_賣出天數3\nLF_賣出獲利率3\n價格")];	                   
                }
            }
            
             			
			/*
			[picka2 addObject:@"移動均線1"];	
			[picka2 addObject:@"移動均線2"];	
			[picka2 addObject:@"移動均線3"];		
			[picka2 addObject:@"移動均線4"];	
			[picka2 addObject:@"移動均線5"];	
			
			[picka2 addObject:@"動態線狀態1"];	
			[picka2 addObject:@"動態線狀態2"];	
			[picka2 addObject:@"動態線狀態3"];
			[picka2 addObject:@"動態線狀態1\n動態線狀態2\n動態線狀態3"];	
			
			[picka2 addObject:@"動態線訊號1"];	
			[picka2 addObject:@"動態線訊號2"];	
			[picka2 addObject:@"動態線訊號3"];	
			[picka2 addObject:@"動態線訊號1\n動態線訊號2\n動態線訊號3"];	
			 */
			 
		}
		if (picka3==nil) {
			picka3=[[NSMutableArray alloc] init];
			picka3=[picka2 mutableCopy];	
		}
		
	}
	
	//需要計算的欄位:-(void)Caluate_TableIndicator 
	if (needCalcuateTableIndicator==nil) {
        needCalcuateTableIndicator=[[NSMutableArray alloc] init];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"5Day Change%", @"5日漲跌幅")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"10Day Change%", @"10日漲跌幅")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"20Day Change%", @"20日漲跌幅")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"60Day Change%", @"60日漲跌幅")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"120Day Change%", @"120日漲跌幅")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"240Day Change%", @"240日漲跌幅")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"Week Change%", @"週漲跌幅")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"Month Change%", @"月漲跌幅")];		
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"Quarter Change%", @"季漲跌幅")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"Year Change%", @"年漲跌幅")];	
        
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Signal1", @"LF_訊號1")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Break P1", @"LF_關鍵價位1")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Signal2", @"LF_訊號2")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Break P2", @"LF_關鍵價位2")];	
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Signal3", @"LF_訊號3")];
        [needCalcuateTableIndicator addObject: NSLocalizedString(@"LF_Break P3", @"LF_關鍵價位3")];	
        
        [needCalcuateTableIndicator  addObject:NSLocalizedString(@"LF_Action1", @"LF_動作1")];			
        [needCalcuateTableIndicator  addObject:NSLocalizedString(@"LF_Action2", @"LF_動作2")];					
        [needCalcuateTableIndicator  addObject:NSLocalizedString(@"LF_Action3", @"LF_動作3")];	
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongDay1", @"LF_買入天數1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongDay2", @"LF_買入天數2")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongDay3", @"LF_買入天數3")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgDay1", @"LF_賣出天數1")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgDay2", @"LF_賣出天數2")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgDay3", @"LF_賣出天數3")];		
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongProfit1", @"LF_買入獲利率1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongProfit2", @"LF_買入獲利率2")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_LongProfit3", @"LF_買入獲利率3")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgProfit1", @"LF_賣出獲利率1")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgProfit2", @"LF_賣出獲利率2")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"LF_ShortgProfit3", @"LF_賣出獲利率3")];					
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_FAMA1", @"MESA_FAMA1")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_MAMA1", @"MESA_MAMA1")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_FAMA2", @"MESA_FAMA2")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_MAMA2", @"MESA_MAMA2")];				
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_FAMA3", @"MESA_FAMA3")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_MAMA3", @"MESA_MAMA3")];		
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Signal1", @"MESA_訊號1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Signal2", @"MESA_訊號2")];					
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Signal3", @"MESA_訊號3")];			
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Action1", @"MESA_動作1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Action2", @"MESA_動作2")];					
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_Action3", @"MESA_動作3")];		
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongDay1", @"MESA_買入天數1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongDay2", @"MESA_買入天數2")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongDay3", @"MESA_買入天數3")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgDay1", @"MESA_賣出天數1")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgDay2", @"MESA_賣出天數2")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgDay3", @"MESA_賣出天數3")];		
        
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongProfit1", @"MESA_買入獲利率1")];			
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongProfit2", @"MESA_買入獲利率2")];
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_LongProfit3", @"MESA_買入獲利率3")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgProfit1", @"MESA_賣出獲利率1")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgProfit2", @"MESA_賣出獲利率2")];	
        [needCalcuateTableIndicator addObject:NSLocalizedString(@"MESA_ShortgProfit3", @"MESA_賣出獲利率3")];		
        
        
    }
	
	
	//表格報價指標
	isCaluateTableIndicatorNow=NO;
	Total_CaluateTableIndicator=0;
	index_CaluateTableIndicator=0;		
	
	isDownloadQuoteNow=NO;	
	
	isInOptimize=NO;	
	havefirstusenavcontroller=NO;
	
	Gdwm=@"d";
	
 	isRuningRefreshQuoteTable=NO;
	canRuningRefreshQuoteTable=NO;
    /*
    ActivityIndicator=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(130,210, 60, 60)];	
	ActivityIndicator.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhiteLarge;
	
	[navdelegete.view addSubview:ActivityIndicator];	
	*/
    
	downhistoryindex=-1;	
	
		
	//設定 Table Header 的初始化高度
	TableHeigh=40;
	//設定 Tableview 顏色
	UITableView *tv;
	tv=[self tableView];
	 
    
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];        
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            
            
            //顏色設定需要浮點 因此要有小數點
            //背景顏色
            tv.backgroundColor= [UIColor colorWithRed:1.0/255.0 green:14.0/255.0 blue:30.0/255.0 alpha:1.0];	
            //tv.backgroundView = [[[tablecellgradent alloc] initWithFrame:CGRectZero] autorelease];
            
            //分隔線顏色
            tv.separatorColor=[UIColor colorWithRed:1.0/255.0 green:14.0/255.0 blue:30.0/255.0 alpha:1.0];
            tv.alpha=1.0;            
        }
        else{
            //開始LF
            
            
            //顏色設定需要浮點 因此要有小數點
            //背景顏色
            tv.backgroundColor= [UIColor colorWithRed:16.0/255.0 green:42.0/255.0 blue:64.0/255.0 alpha:1.0];	
            //tv.backgroundView = [[[tablecellgradent alloc] initWithFrame:CGRectZero] autorelease];
            
            //分隔線顏色
            tv.separatorColor=[UIColor colorWithRed:16.0/255.0 green:42.0/255.0 blue:64.0/255.0 alpha:1.0];
            tv.alpha=1.0; 
            
            
            
        }
    }
    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                 
           
    if ([[prefs objectForKey:@"CanDragToRefreshQuoteTable"] boolValue]==YES)  {                 
        
        //標記:Drag Refresh HeaderView實體化 與背景顏色
        //原點的y為0.0f - tv.bounds.size.height 高度為tv.bounds.size.height 就是把整個的headerView 往上移動搬移向上
        
        headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - tv.bounds.size.height, 320.0f, tv.bounds.size.height)];
        headerView.backgroundColor = [UIColor underPageBackgroundColor];
        [tv addSubview:headerView];
        [headerView release];
        
        tv.showsVerticalScrollIndicator = YES;  
        
        
    }   
      
    //標記:進度指示器 實體化(StockTableQuote.m)
    acv=[[ActivityIndicator_view alloc] init];
    acv.hidden=YES;
    acv.progbar.hidden=YES;
    acv.label_state.text=NSLocalizedString(@"Loading...","載入中.....");   
    [tv addSubview:acv];
    [acv release];
     
	
	//畫面呈現時上網取的報價資料
	
	isfirstQuote=YES;
	[self refeshTableQuote];
	
	NSLog(@"viewdidload_end");
}
-(void)get_navcontroller:(navcontroller *)nd{
	 
	navdelegete=nd;
	//顯示編輯自選股 功能扭 
	if ([self.market isEqualToString:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")] && ![self.title isEqualToString:NSLocalizedString(@"全部自選股",@"全部自選股")]) {
	 
        
         UIBarButtonItem * editItem;
         editItem = [[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"Edit & Add",@"Edit & Add")   style:UIBarButtonItemStyleBordered target:self action:@selector(editWatchList)];
               
        /*
        UIBarButtonItem *editButton = [[UIBarButtonItem alloc]             
									   initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self
									   action:@selector(editWatchList)]; 
        */
    	self.navigationItem.rightBarButtonItem =editItem;	
        [editItem release];
	}
	else {
		//設定
		/*
		UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
		[infoButton addTarget:self action:@selector(showSetup) forControlEvents:UIControlEventTouchUpInside];
		self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];
		*/
		
	}
     
	
	
	
}
#pragma mark -
#pragma mark  報價表格欄位計算
-(void)calcuate_Table_Indicator{
	 
	if (isCaluateTableIndicatorNow==NO) {
		 		
		isCaluateTableIndicatorNow=YES;
		Total_CaluateTableIndicator=[download_data_obj count];
		index_CaluateTableIndicator=0;	
		//執行進度顯示器	
		 //calcuate_stop=NO;
		[self presentSheet];		
        NSLog(@"[self presentSheet] 1");
		
	}
	NSLog(@"a1"); 
	if (index_CaluateTableIndicator<Total_CaluateTableIndicator  && calcuate_stop==NO ) {
	NSLog(@"a2");         
        
		DataObject *ob;
		ob=[download_data_obj objectAtIndex:index_CaluateTableIndicator];
		ob.activity= [NSNumber numberWithBool:YES];
		[self.tableView reloadData];
		//強迫報價表資料 用日資料
		ob.dwm=@"d";
		
		[self incrementBara_CaluateTableIndicator:ob.symbol];
		//NSLog(@"!!!!!!!=%i  %@",index_CaluateTableIndicator,ob.symbol);
		 	
		//啓動object計算欄位指標值
		ob.delgete=self;
		ob.havetocalcuateTableIndicator=haveToTableCaluateIndicator;
		
		[ob getYahooHistroryDatagraphindex:0 
							   writetofile:YES 
								 drawChart:NO 
				closeCellActivityIndicator:YES
						  isuseNavagarator:NO 
					  isresetGraphLocation:NO 
								isOptimize:NO
				   isCaluateTableIndicator:YES]; //進行最佳化			
		
		
		
	}
	else {
		//下載結束
		isCaluateTableIndicatorNow=NO;	
		[self.tableView reloadData];
		//將進度畫面銷除
		[self.baseSheet dismissWithClickedButtonIndex:0 animated:YES]; 
		
	}

	
	
	

}


#pragma mark -
#pragma mark  報價設定
- (void)aflipsideViewControllerDidFinish:(StockTableQuoteSetup *)controller identify:(NSString *)identfy{
    if ([identfy isEqualToString:@"slideOut"]) {
		//NSLog(@"******slideOut");
       
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){}
        
        else{
            
            [self dismissModalViewControllerAnimated:YES];	
        }
        
         
        calcuate_stop=NO;
      //  NSLog(@"*****aaaaaaa");
		[self refeshTableQuote];
		//NSLog(@"******bbbbbbb");
        
        //[self.tableView reloadData];
		
	}
	else if([identfy isEqualToString:@"slideOut_opt"]){
    	//NSLog(@"*******slideOut_opt");
        [self dismissModalViewControllerAnimated:YES];	
		[self refreshALL:nil];
	}
}
-(void)showSetup{
	
	NSLog(@"showSetup"); 
    
	StockTableQuoteSetup *controller = [[StockTableQuoteSetup alloc] initWithpicka1:picka1 picka2:picka2 picka3:picka3 objecta:download_data_obj];	
	
	controller.delegate = self;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
       
        
        if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
            //垂直
            
            //主圖消失            
            [[(AppDelegate * )AppleDeglate Master_popController]  dismissPopoverAnimated:YES]; 
            
            
            controller.AppleDeglate=AppleDeglate;
            //顯示增加群組視窗
            controller.modalPresentationStyle=UIModalPresentationFormSheet;
            [self presentModalViewController:controller animated:YES];             
           
            
            
        }
        else{
            //水平
            
            
            UIPopoverController* popController =  [[UIPopoverController alloc] initWithContentViewController:controller]  ;
            
            controller.delegate_UIPopoverController=popController;
            [popController release];
            
            popController.popoverContentSize = CGSizeMake(320,460);
            
            CGRect rect = CGRectMake( 0,0,2,2);    
            
            [popController presentPopoverFromRect:rect
                                           inView:self.view
                         permittedArrowDirections:UIPopoverArrowDirectionAny 
                                         animated:YES];                      
            
            ///[popController release];
        }        
        
        
        
        
        
        
             
    }    
    else{
    	controller.modalTransitionStyle =UIModalTransitionStyleFlipHorizontal; //UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
	    
    
    }
        
    
    
    
	[controller release];	
}
-(void)editWatchList{
	//編輯自選股視窗
	editWatchList *ediw;
	ediw=[[editWatchList alloc] initWithWatchListCode:data_code WatchListName:data_name WatchList_id_class:data_id_class watchlistTitle:self.title];
	 
	ediw.delegate=self;
    ediw.AppleDeglate=AppleDeglate;
	ediw.modalTransitionStyle =UIModalTransitionStyleCrossDissolve; //UIModalTransitionStyleFlipHorizontal;
	[ediw get_navcontroller:navdelegete];
	 
	[navdelegete pushViewController:ediw animated:YES];
	
	[ediw release];		

}
- (void)editWatchListControllerDidFinish:(editWatchList *)controller{
	//編輯自選股之後 啓動的動作
	NSLog(@"編輯自選股之後 啓動的動作");
    [self dismissModalViewControllerAnimated:YES];	
    isfirstQuote=YES;
	
    [self refeshTableQuote];
	[self.delgete refreshWatchList];
    
    
}
#pragma mark -
#pragma mark 如果新增家欄位格式 在此函數新增格式內容
//如果新增家欄位格式 在此函數新增格式內容
-(void)setStockTableQuoteCell:(StockTableQuoteCell *)wcell 
					  identfy:(NSString *)identfy 
					dataobjet:(DataObject *)ob 
				   UILabel_cr:(UILabel *)cr 
				   sortString:(NSString *)sortString{
	
   //報價簡單用
    UIColor *upcolor=[UIColor whiteColor];
    UIColor *downcolor=[UIColor whiteColor];
   //計算用顏色
    UIColor *cupcolor=[UIColor whiteColor];
    UIColor *cdowncolor=[UIColor whiteColor];
    
    //上漲
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];    
    if ([[prefs objectForKey:@"upColor"] isEqualToString:@"greenColor" ] ) {
        upcolor=[UIColor colorWithRed:126.0/255.0 green:181.0/255.0 blue:41.0/255.0 alpha:1];	
        cupcolor=[UIColor greenColor];
    } 
    else if ([[prefs objectForKey:@"upColor"] isEqualToString:@"redColor" ] ) {
        upcolor=[UIColor colorWithRed:209.0/255.0 green:42.0/255.0 blue:47.0/255.0 alpha:1];	
        cupcolor=[UIColor redColor];
 
    }         
    //下跌
    if ([[prefs objectForKey:@"downColor"] isEqualToString:@"redColor" ] ) {
        downcolor=[UIColor colorWithRed:209.0/255.0 green:42.0/255.0 blue:47.0/255.0 alpha:1];	
        cdowncolor=[UIColor redColor];
    } 
    else if ([[prefs objectForKey:@"downColor"] isEqualToString:@"greenColor" ] ) {
        downcolor=[UIColor colorWithRed:126.0/255.0 green:181.0/255.0 blue:41.0/255.0 alpha:1];	 
        cdowncolor=[UIColor greenColor];
    }          
    
    
    
    
    cr.textAlignment=UITextAlignmentLeft;	
	
	if([identfy isEqualToString:NSLocalizedString(@"Name", @"名稱")]){
		cr.text=ob.name;
	}
	else if([identfy isEqualToString:NSLocalizedString(@"Symbol", @"代號")]){
		//標記:是否移除交易所碼        
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
       
        if ([[prefs objectForKey:@"isRemoveExchangeCode"] boolValue]==YES) {
            //字串分割
            NSArray *code_exchange_Array = [ob.symbol componentsSeparatedByString:@"."];
            if ([code_exchange_Array count]==2) {
                cr.text=[code_exchange_Array objectAtIndex:0];
            }
            else{
                cr.text=ob.symbol;          
            }
             
        }
        else {
            cr.text= ob.symbol;
        }        
        
       
	}
	else if([identfy isEqualToString:NSLocalizedString(@"Class", @"分類")]){
		
        cr.text=ob.id_class;
		
	}		
	
	else if([identfy isEqualToString:NSLocalizedString(@"Price", @"價格")]){
		 
		cr.text=ob.lastprice;
		
		cr.textAlignment=UITextAlignmentCenter;			
	}
	else if([identfy isEqualToString:NSLocalizedString(@"Time", @"時間")]){
		cr.text=ob.tradetime;
		cr.textAlignment=UITextAlignmentCenter;			
	}
	else  if([identfy isEqualToString:NSLocalizedString(@"Date", @"日期")]){
		//將日期格式MM/dd/yyyy 轉成為MM/dd/
		 
        NSDate *theDate = [[NSDateFormatter yahooDailyDateFormatter] dateFromString:ob.tradedate];
		NSDateFormatter* df = [[NSDateFormatter alloc]init];
		[df setDateFormat:@"MM/dd"];
		NSString *result = [df stringFromDate:theDate];
        [df release];
        
        cr.text= result;
		cr.textAlignment=UITextAlignmentCenter;			
		//[df release];		
		
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"Change", @"漲跌")]){
		NSString *updowns;
		updowns=ob.updown;
		NSDecimalNumber *num_updown=[NSDecimalNumber decimalNumberWithString:@"0"];
		if ([updowns hasPrefix:@"+" ] || [updowns hasPrefix:@"-" ]) {
			NSString *y;
			y=[updowns stringByReplacingOccurrencesOfString:@"+" withString:@""];
			y=[y stringByReplacingOccurrencesOfString:@"-" withString:@""];
			num_updown= [NSDecimalNumber decimalNumberWithString:y];
			//NSLog([num_updown stringValue]);
		}
		
		//比較首部
		if ([updowns hasPrefix:@"+" ] ) {
			cr.backgroundColor=upcolor;	
			cr.text=[@"+" stringByAppendingString: [num_updown stringValue]];
		}
		else if([updowns hasPrefix:@"-" ]){
			cr.backgroundColor=downcolor;	
			cr.text=[@"-" stringByAppendingString: [num_updown stringValue]];
		}
		else if([updowns hasPrefix:@"N/A"]){
			cr.backgroundColor=[UIColor colorWithRed:165.0/255.0 green:163.0/255.0 blue:245.0/255.0 alpha:1];	
			cr.text=ob.updown;
		}
		else {
			cr.backgroundColor=[UIColor colorWithRed:103.0/255.0 green:103.0/255.0 blue:103.0/255.0 alpha:1];	
			cr.text=@"0.0";
		}		
		cr.textColor=[UIColor whiteColor];
		cr.layer.cornerRadius=5;
		cr.textAlignment=UITextAlignmentCenter;
		//NSLog(@"high=%f",cr.frame.size.height);
		if (cr.frame.size.height==40) {
			cr.font=[UIFont boldSystemFontOfSize:15];
		}
		else {
			cr.font=[UIFont boldSystemFontOfSize:12];			
		}
		
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"Change%", @"漲跌福")]){
		NSString *updowns;
		updowns=ob.updown;
		//NSDecimalNumber *num_updown; 
		if ([updowns hasPrefix:@"+" ] || [updowns hasPrefix:@"-" ]) {
			//NSString *y;
			//y=[updowns stringByReplacingOccurrencesOfString:@"+" withString:@""];
			//y=[y stringByReplacingOccurrencesOfString:@"-" withString:@""];
			//num_updown= [NSDecimalNumber decimalNumberWithString:y];
			//NSLog([num_updown stringValue]);
		}
		
		//比較首部
		if ([updowns hasPrefix:@"+" ] ) {
			cr.backgroundColor=upcolor;//[UIColor colorWithRed:209.0/255.0 green:42.0/255.0 blue:47.0/255.0 alpha:1];	
			cr.text=ob.updownPercent;
		}
		else if([updowns hasPrefix:@"-" ]){
			cr.backgroundColor=downcolor;//[UIColor colorWithRed:126.0/255.0 green:181.0/255.0 blue:41.0/255.0 alpha:1];	
			cr.text=ob.updownPercent;
		}
		else if([updowns hasPrefix:@"N/A"]){
			cr.backgroundColor=[UIColor colorWithRed:165.0/255.0 green:163.0/255.0 blue:245.0/255.0 alpha:1];	
			cr.text=ob.updownPercent;
		}
		else {
			cr.backgroundColor=[UIColor colorWithRed:103.0/255.0 green:103.0/255.0 blue:103.0/255.0 alpha:1];	
			cr.text=@"0.0";
		}		
		cr.textColor=[UIColor whiteColor];
		cr.layer.cornerRadius=5;
		cr.textAlignment=UITextAlignmentCenter;
		cr.font=[UIFont boldSystemFontOfSize:12];
		
		//NSLog(@"high=%f",cr.frame.size.height);
		if (cr.frame.size.height==40) {
			cr.font=[UIFont boldSystemFontOfSize:15];
		}
		else {
			cr.font=[UIFont boldSystemFontOfSize:12];			
		}
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"Volume", @"成交量")]){
		cr.text=ob.volume_yahoo;	
		cr.textAlignment=UITextAlignmentCenter;		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"EPS Current Year", @"今年EPS")]){
		cr.text=ob.EPS_Estimate_Current_Year_yahoo;
		cr.textAlignment=UITextAlignmentCenter;		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"PE Next Year", @"次年PE")]){
		cr.text=ob.Price_EPS_Estimate_Next_Year_yahoo;		
		cr.textAlignment=UITextAlignmentCenter;		
	}	
	else  if([identfy isEqualToString:NSLocalizedString(@"5Day Change%", @"5日漲跌幅")]){
		cr.text= [ob.ChangePercent5day  stringByAppendingString:@"%"] ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.ChangePercent5day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent5day floatValue] < 0){
		    cr.textColor=cdowncolor;
		
		}
		else {
			cr.textColor=[UIColor grayColor];
		}
	
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"10Day Change%", @"10日漲跌幅")]){
		cr.text=[ ob.ChangePercent10day stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;
		
		if ([ob.ChangePercent10day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent10day floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"20Day Change%", @"20日漲跌幅")]){
		cr.text=[ ob.ChangePercent20day stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;		
		
		if ([ob.ChangePercent20day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent20day floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"60Day Change%", @"60日漲跌幅")]){
		cr.text=[ ob.ChangePercent60day  stringByAppendingString:@"%"] ;		
		cr.textAlignment=UITextAlignmentCenter;	
		if ([ob.ChangePercent60day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent60day floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"120Day Change%", @"120日漲跌幅")]){
		cr.text=[ ob.ChangePercent120day stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;	
		
		if ([ob.ChangePercent120day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent120day floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"240Day Change%", @"240日漲跌幅")]){
		cr.text=[ ob.ChangePercent240day stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;		
		
		if ([ob.ChangePercent240day floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercent240day floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
		
		
	}	
	else  if([identfy isEqualToString:NSLocalizedString(@"Week Change%", @"週漲跌幅")]){
		cr.text= [ob.ChangePercentWeek stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;	
		
		
		if ([ob.ChangePercentWeek floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercentWeek floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"Month Change%", @"月漲跌幅")]){
		cr.text= [ob.ChangePercentMonth stringByAppendingString:@"%"] ;		
		cr.textAlignment=UITextAlignmentCenter;		
		
		if ([ob.ChangePercentMonth floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercentMonth floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"Quarter Change%", @"季漲跌幅")]){
		cr.text= [ob.ChangePercentQuarter  stringByAppendingString:@"%"] ;		
		cr.textAlignment=UITextAlignmentCenter;	
		
		if ([ob.ChangePercentQuarter floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercentQuarter floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"Year Change%", @"年漲跌幅")]){
		cr.text= [ob.ChangePercentYear stringByAppendingString:@"%"]  ;		
		cr.textAlignment=UITextAlignmentCenter;		
		
		if ([ob.ChangePercentYear floatValue] > 0) {
			cr.textColor=cupcolor;
		}
		else if([ob.ChangePercentYear floatValue] < 0){
		    cr.textColor=cdowncolor;
			
		}
		else {
			cr.textColor=[UIColor grayColor];
		}				
		
		
	}		
	
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Signal1", @"LF_訊號1")]){
		cr.text=  ob.LF_Signal1   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b1 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}

		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Break P1", @"LF_關鍵價位1")]){
		cr.text=  ob.LF_BreakP1    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b1 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Signal2", @"LF_訊號2")]){
		cr.text=  ob.LF_Signal2   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b2 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
		
		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Break P2", @"LF_關鍵價位2")]){
		cr.text=  ob.LF_BreakP2    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b2 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Signal3", @"LF_訊號3")]){
		cr.text=  ob.LF_Signal3   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b3 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Break P3", @"LF_關鍵價位3")]){
		cr.text=  ob.LF_BreakP3    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.cLF_b3 intValue]==1) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Action1", @"LF_動作1")]){
		cr.text=  ob.LF_Action1   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_Action1 isEqualToString:@"1"]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString(@"Long Now",@"現在作多");
		}
		else if([ob.LF_Action1 isEqualToString:@"-1"]) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString(@"Short Now",@"現在放空");
		}		
		else{
		    cr.textColor=[UIColor grayColor];	
			cr.text=NSLocalizedString( @"No Action",@"無動作");
		}
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Action2", @"LF_動作2")]){
		cr.text=  ob.LF_Action2   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_Action2 isEqualToString:@"1"]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString(@"Long Now",@"現在作多");
		}
		else if([ob.LF_Action2 isEqualToString:@"-1"]) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString(@"Short Now",@"現在放空");
		}		
		else{
		    cr.textColor=[UIColor grayColor];	
			cr.text=NSLocalizedString( @"No Action",@"無動作");
		}
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_Action3", @"LF_動作3")]){
		cr.text=  ob.LF_Action3   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_Action3 isEqualToString:@"1"]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString(@"Long Now",@"現在作多");
		}
		else if([ob.LF_Action3 isEqualToString:@"-1"]) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString(@"Short Now",@"現在放空");
		}		
		else{
		    cr.textColor=[UIColor grayColor];	
			cr.text=NSLocalizedString( @"No Action",@"無動作");
		}
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongDay1", @"LF_買入天數1")]){
		cr.text=  ob.LF_LongDay1    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
		 	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongDay2", @"LF_買入天數2")]){
		cr.text=  ob.LF_LongDay2     ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongDay3", @"LF_買入天數3")]){
		cr.text=  ob.LF_LongDay3     ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgDay1", @"LF_賣出天數1")]){
		cr.text=  ob.LF_ShortgDay1    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgDay2", @"LF_賣出天數2")]){
		cr.text=  ob.LF_ShortgDay2    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgDay3", @"LF_賣出天數3")]){
		cr.text=  ob.LF_ShortgDay3    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];	
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongProfit1", @"LF_買入獲利率1")]){
		cr.text=  [ob.LF_LongProfit1 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_LongProfit1 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_LongProfit1 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}				
		
		 
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongProfit2", @"LF_買入獲利率2")]){
		cr.text=  [ob.LF_LongProfit2 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_LongProfit2 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_LongProfit2 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}				
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_LongProfit3", @"LF_買入獲利率3")]){
		cr.text=  [ob.LF_LongProfit3 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_LongProfit3 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_LongProfit3 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}				
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgProfit1", @"LF_賣出獲利率1")]){
		cr.text=  [ob.LF_ShortgProfit1 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_ShortgProfit1 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_ShortgProfit1 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}		
		 
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgProfit2", @"LF_賣出獲利率2")]){
		cr.text=  [ob.LF_ShortgProfit2 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_ShortgProfit2 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_ShortgProfit2 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"LF_ShortgProfit3", @"LF_賣出獲利率3")]){
		cr.text=  [ob.LF_ShortgProfit3 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.LF_ShortgProfit3 floatValue]>0) {
			cr.textColor=cupcolor;
		}
		else if([ob.LF_ShortgProfit3 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else{
		    cr.textColor=[UIColor grayColor];		
		}		
		
	}			

	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_FAMA1", @"MESA_FAMA1")]){
		cr.text=  ob.MESA_FAMA1   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_MAMA1 floatValue]>[ob.MESA_FAMA1 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_MAMA1", @"MESA_MAMA1")]){
		cr.text=  ob.MESA_MAMA1   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_MAMA1 floatValue]>[ob.MESA_FAMA1 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}				
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_FAMA2", @"MESA_FAMA2")]){
		cr.text=  ob.MESA_FAMA2   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_MAMA2 floatValue]>[ob.MESA_FAMA2 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}				
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_MAMA2", @"MESA_MAMA2")]){
		cr.text=  ob.MESA_MAMA2   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_MAMA2 floatValue]>[ob.MESA_FAMA2 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}			
		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_FAMA3", @"MESA_FAMA3")]){
		cr.text=  ob.MESA_FAMA3   ;		
		cr.textAlignment=UITextAlignmentCenter;	
		
		if ([ob.MESA_MAMA3 floatValue]>[ob.MESA_FAMA3 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}			
		
		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_MAMA3", @"MESA_MAMA3")]){
		cr.text=  ob.MESA_MAMA3   ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_MAMA3 floatValue]>[ob.MESA_FAMA3 floatValue]) {
			cr.textColor=cupcolor;
		}
		else {
			cr.textColor=cdowncolor;
		}			
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Signal1", @"MESA_訊號1")]){
		 			
		if ([ob.MESA_MAMA1 floatValue]>[ob.MESA_FAMA1 floatValue]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long",@"多頭") ;;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		
	}				
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Signal2", @"MESA_訊號2")]){
		if ([ob.MESA_MAMA2 floatValue]>[ob.MESA_FAMA2 floatValue]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long",@"多頭") ;;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Signal3", @"MESA_訊號3")]){
		if ([ob.MESA_MAMA3 floatValue]>[ob.MESA_FAMA3 floatValue]) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long",@"多頭") ;;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Action1", @"MESA_動作1")]){
		if ([ob.MESA_bs1 intValue]==1) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long Now",@"現在作多") ;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else if([ob.MESA_bs1 intValue]==-1) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short Now",@"現在放空");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		else {
			cr.textColor=[UIColor grayColor];
			cr.text=NSLocalizedString( @"No Action",@"無動作");	
			cr.textAlignment=UITextAlignmentCenter;					
		}
		//cr.text=ob.MESA_bs1;

	}				
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Action2", @"MESA_動作2")]){
		if ([ob.MESA_bs2 intValue]==1) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long Now",@"多頭") ;;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else if([ob.MESA_bs2 intValue]==-1) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short Now",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		else {
			cr.textColor=[UIColor grayColor];
			cr.text=NSLocalizedString( @"No Action",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;					
		}
		 		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_Action3", @"MESA_動作3")]){
		if ([ob.MESA_bs3 intValue]==1) {
			cr.textColor=cupcolor;
			cr.text=NSLocalizedString( @"Long Now",@"多頭") ;;
			cr.textAlignment=UITextAlignmentCenter;				
		}
		else if([ob.MESA_bs3 intValue]==-1) {
			cr.textColor=cdowncolor;
			cr.text=NSLocalizedString( @"Short Now",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;				
		}			
		else {
			cr.textColor=[UIColor grayColor];
			cr.text=NSLocalizedString( @"No Action",@"空頭");	
			cr.textAlignment=UITextAlignmentCenter;					
		}
		 	
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongDay1", @"MESA_買入天數1")]){
		cr.text=  ob.MESA_LongDay1    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
		 
		
	}		
    else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongDay2", @"MESA_買入天數2")]){
		cr.text=  ob.MESA_LongDay2     ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];

		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongDay3", @"MESA_買入天數3")]){
		cr.text=  ob.MESA_LongDay3     ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];

		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgDay1", @"MESA_賣出天數1")]){
		cr.text=  ob.MESA_ShortgDay1    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgDay2", @"MESA_賣出天數2")]){
		cr.text=  ob.MESA_ShortgDay2    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
	
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgDay3", @"MESA_賣出天數3")]){
		cr.text=  ob.MESA_ShortgDay3    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		cr.textColor=[UIColor whiteColor];
	
		
	}			
	
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongProfit1", @"MESA_買入獲利率1")]){
		cr.text=  [ob.MESA_LongProfit1 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_LongProfit1 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_LongProfit1 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongProfit2", @"MESA_買入獲利率2")]){
		cr.text=  [ob.MESA_LongProfit2 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_LongProfit2 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_LongProfit2 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}

		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_LongProfit3", @"MESA_買入獲利率3")]){
		cr.text=  [ob.MESA_LongProfit3 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_LongProfit3 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_LongProfit3 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgProfit1", @"MESA_賣出獲利率1")]){
	    cr.text=  [ob.MESA_ShortgProfit1 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_ShortgProfit1 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_ShortgProfit1 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}		
		
		
		
	}		
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgProfit2", @"MESA_賣出獲利率2")]){
		cr.text=  [ob.MESA_ShortgProfit2 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_ShortgProfit2 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_ShortgProfit2 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}		
		
	}			
	else  if([identfy isEqualToString:NSLocalizedString(@"MESA_ShortgProfit3", @"MESA_賣出獲利率3")]){
		cr.text=  [ob.MESA_ShortgProfit3 stringByAppendingString:@"%"]    ;		
		cr.textAlignment=UITextAlignmentCenter;		
		if ([ob.MESA_ShortgProfit3 floatValue]>0){
			cr.textColor=cupcolor;
		}
		else if ([ob.MESA_ShortgProfit3 floatValue]<0){
			cr.textColor=cdowncolor;
		}	
		else {
		    cr.textColor=[UIColor grayColor];
		}		
		
	}			
	
	
	else {
		cr.text =@"";
	}
	
	cr.text=[cr.text stringByAppendingString:sortString];
	if (![sortString isEqualToString:@""]) {
		 //如果是排序欄位則字體放大
		cr.font=[UIFont boldSystemFontOfSize:cr.font.pointSize+0.5];
	}
	
	
}
#pragma mark -
#pragma mark 表格數量與資料來源與外觀設定

 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
	         return 1;
   
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     	
	return [download_data_obj count] ;
	
}
// Customize the appearance of table view cells.


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     
   
    
	static NSString *CellIdentifier = @"StockTableQuoteCell";
    
    StockTableQuoteCell *cell =(StockTableQuoteCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]
    ;
   
    DataObject *ob;
	if (indexPath.row>=[download_data_obj count]) {
        return cell;
    }
    else{
        ob=[download_data_obj objectAtIndex:indexPath.row]; 
    }
     
    
    
    
    if (cell == nil) {
        cell = [[[StockTableQuoteCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    
    
    int c3Length=0;
    
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
   
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //開始MESA
            
            //標記:表格內展開出現日內走勢圖 刷新表格的動作            
           
            if ([expand_table_code indexOfObject:[NSString stringWithFormat:@"%i",indexPath.row]]!=NSNotFound ) {
                
                //顯示+ -鈕
                cell.zoom.frame= CGRectMake(0, 0, 9, tablecell_high_zoom_out) ;
                cell.zoom.text=@"-";
                cell.zoom.textAlignment=UITextAlignmentCenter;
                cell.zoom.font=[UIFont boldSystemFontOfSize:9];
                
                             
                [cell get_preday_close:  [ob.lastprice floatValue]-[ob.updown floatValue]  ];
                
                //提供cell 已經取出的日內資料參考位置
               //將已經取出的日內圖資料放在 StockTableQuote 內
               //標記:日內走勢圖記憶體宣告實體與消滅 方法執行                
                [cell get_cell_intraday_data:intraday_data 
                         intraday_data_code:intraday_data_code 
                        intraday_data_x_time:intraday_data_x_time
                     intraday_graph_x_length:intraday_graph_x_length 
                      intraday_graph_x_high:intraday_graph_x_high  
                       intraday_graph_x_low:intraday_graph_x_low 
                intraday_graph_lastdayClose:intraday_graph_lastdayClose 
                 intraday_graph_volume_high:intraday_graph_volume_high 
                  intraday_graph_volume_low:intraday_graph_volume_low 
              intraday_graph_selected_right:intraday_graph_selected_right 
               intraday_graph_selected_left:intraday_graph_selected_left  ];
               //進行繪圖日內圖 
              
                [cell drawGraph:ob.symbol];
                
                
            }
            else
            {
                cell.zoom.frame= CGRectMake(0, 0, 9, 60) ;
                cell.zoom.text=@"+";
                cell.zoom.textAlignment=UITextAlignmentCenter; 
                cell.zoom.font=[UIFont boldSystemFontOfSize:9];  
               
                //隱藏下半部 時啓動的動作
                [cell hiden_secondTable];
            }
            
                                   
            cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; 
            c3Length=80;
        }
        else{
            //開始LF
            //隱藏 + -
            cell.zoom.backgroundColor=[UIColor clearColor]; 
            
            c3Length=100;
        }
    }
    
       
    
	
    
    
    
    //第一行
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
	
	//第1列欄位
	{
		//解析 有幾行				
		NSArray *csvLinesR0 = [[picka1 objectAtIndex:[[prefs objectForKey: @"tableR0" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
	
		 
		NSString *titleupdownC0R0=@"";
		NSString *titleupdownC0R1=@"";	
		NSString *titleupdownC0R2=@"";	
		 
		//排序註解使用
		if (select_col_index==0) {
			switch (select_col_index_row-1) {
				case 0:{
					if (select_col_index_row_updwon==1) {
						titleupdownC0R0=@"▲";
					}
					else {
						titleupdownC0R0=@"▼";				
					}
					break;
				}
				case 1:{
					if (select_col_index_row_updwon==1) {
						titleupdownC0R1=@"▲";
					}
					else {
						titleupdownC0R1=@"▼";				
					}
					
					
					break;
				}	
				case 2:{
					if (select_col_index_row_updwon==1) {
						titleupdownC0R2=@"▲";
					}
					else {
						titleupdownC0R2=@"▼";				
					}
					break;
				}
					
				default:
					break;
			}		
		}		
		
		//輸入到cell
		if ([csvLinesR0 count]==1) {
			cell.c0r0.frame=CGRectMake(10, 10, 100, 40);
			
			cell.c0r0.font=[UIFont boldSystemFontOfSize:15];
			cell.c0r0.backgroundColor=[UIColor clearColor];
			cell.c0r0.textColor=[UIColor whiteColor];
			cell.c0r0.numberOfLines=3;
			//輸出內容
			{ 
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r0 
								  sortString:titleupdownC0R0 ];
				cell.c0r0.hidden=NO;
				cell.c0r1.hidden=YES;
				cell.c0r2.hidden=YES;
				
			}			
		}
		else if ([csvLinesR0 count]==2) {
			cell.c0r0.frame=CGRectMake(10, 10, 100, 20);	
			cell.c0r1.frame=CGRectMake(10, 32, 100, 20);
			 
			
			cell.c0r0.numberOfLines=2;
			cell.c0r1.numberOfLines=2;
			cell.c0r0.font=[UIFont boldSystemFontOfSize:15];
			cell.c0r1.font=[UIFont boldSystemFontOfSize:15];					
			
			cell.c0r0.backgroundColor=[UIColor clearColor];
			cell.c0r1.backgroundColor=[UIColor clearColor];
			
			cell.c0r0.textColor=[UIColor whiteColor];
			cell.c0r1.textColor=[UIColor yellowColor];	
			//輸出內容
			{
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r0 
								  sortString:titleupdownC0R0 ];				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r1 
								  sortString:titleupdownC0R1 ];				
				cell.c0r0.hidden=NO;
				cell.c0r1.hidden=NO;
				cell.c0r2.hidden=YES;
				
			}			
		}
		else if ([csvLinesR0 count]==3) {
			cell.c0r0.frame=CGRectMake(10, 0, 100,  20);	
			cell.c0r1.frame=CGRectMake(10, 20, 100, 20);
			cell.c0r2.frame=CGRectMake(10, 40, 100, 20);
			
			cell.c0r0.textColor=[UIColor whiteColor];
			cell.c0r1.textColor=[UIColor yellowColor];				
			cell.c0r2.textColor=[UIColor whiteColor];			
			
			cell.c0r0.font=[UIFont boldSystemFontOfSize:13];
			cell.c0r1.font=[UIFont boldSystemFontOfSize:13];
			cell.c0r2.font=[UIFont boldSystemFontOfSize:13];					
			
			
			cell.c0r0.backgroundColor=[UIColor clearColor];
			cell.c0r1.backgroundColor=[UIColor clearColor];
			cell.c0r2.backgroundColor=[UIColor clearColor];
			//輸出內容
			{
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r0 
								  sortString:titleupdownC0R0 ];
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r1 
								  sortString:titleupdownC0R1 ];
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR0 objectAtIndex:2] 
								   dataobjet:ob 
								  UILabel_cr:cell.c0r2 
								  sortString:titleupdownC0R2];
				
				
				cell.c0r0.hidden=NO;
				cell.c0r1.hidden=NO;
				cell.c0r2.hidden=NO;				
			
			}
			
			 						
			
		}			
		
	}
	 //第2列欄位
	{
		//解析 有幾行				
		NSArray *csvLinesR1 = [[picka2 objectAtIndex:[[prefs objectForKey: @"tableR1" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
		 
		NSString *titleupdownC1R0=@"";
		NSString *titleupdownC1R1=@"";	
		NSString *titleupdownC1R2=@"";	
		 	
		if (select_col_index==1) {
			switch (select_col_index_row-1) {
				case 0:{
					if (select_col_index_row_updwon==1) {
						titleupdownC1R0=@"▲";
					}
					else {
						titleupdownC1R0=@"▼";				
					}
					break;
				}
				case 1:{
					if (select_col_index_row_updwon==1) {
						titleupdownC1R1=@"▲";
					}
					else {
						titleupdownC1R1=@"▼";				
					}
					
					
					break;
				}	
				case 2:{
					if (select_col_index_row_updwon==1) {
						titleupdownC1R2=@"▲";
					}
					else {
						titleupdownC1R2=@"▼";				
					}
					break;
				}
					
				default:
					break;
			}		
		}		
		if ([csvLinesR1 count]==1) {
			cell.c1r0.frame=CGRectMake(110, 10, 100, 40);
			cell.c1r0.font=[UIFont boldSystemFontOfSize:15];
			cell.c1r0.backgroundColor=[UIColor clearColor];
			cell.c1r0.textColor=[UIColor whiteColor];
			cell.c0r0.numberOfLines=3;
			//輸出內容
			{ 
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r0  
								  sortString:titleupdownC1R0 ];		
				cell.c1r0.hidden=NO;
				cell.c1r1.hidden=YES;
				cell.c1r2.hidden=YES;
				
			}					
			
			
			
		}
		else if ([csvLinesR1 count]==2) {
			cell.c1r0.frame=CGRectMake(110, 10, 100, 20);	
			cell.c1r1.frame=CGRectMake(110, 32, 100, 20);
			cell.c1r2.hidden=YES;
			 
			cell.c1r0.font=[UIFont boldSystemFontOfSize:15];
			cell.c1r1.font=[UIFont boldSystemFontOfSize:15];					
			
			
			cell.c1r0.backgroundColor=[UIColor clearColor];
			cell.c1r1.backgroundColor=[UIColor clearColor];
			
			cell.c1r0.textColor=[UIColor whiteColor];
			cell.c1r1.textColor=[UIColor yellowColor];	
			
			//輸出內容
			{
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r0 
								  sortString:titleupdownC1R0 ];				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r1 
								  sortString:titleupdownC1R1 ];
				cell.c1r0.hidden=NO;
				cell.c1r1.hidden=NO;
				cell.c1r2.hidden=YES;
				
			}					
			
			
		}
		else if ([csvLinesR1 count]==3) {
			cell.c1r0.frame=CGRectMake(110, 0, 100,  20);	
			cell.c1r1.frame=CGRectMake(110, 20, 100, 20);
			cell.c1r2.frame=CGRectMake(110, 40, 100, 20);
			
			cell.c1r0.text=[csvLinesR1 objectAtIndex:0];
			cell.c1r1.text=[csvLinesR1 objectAtIndex:1];
			cell.c1r2.text=[csvLinesR1 objectAtIndex:2];
			cell.c1r0.font=[UIFont boldSystemFontOfSize:13];
			cell.c1r1.font=[UIFont boldSystemFontOfSize:13];
			cell.c1r2.font=[UIFont boldSystemFontOfSize:13];
			
			cell.c1r0.backgroundColor=[UIColor clearColor];
			cell.c1r1.backgroundColor=[UIColor clearColor];
			cell.c1r2.backgroundColor=[UIColor clearColor];
			
			cell.c1r0.textColor=[UIColor whiteColor];
			cell.c1r1.textColor=[UIColor yellowColor];				
			cell.c1r2.textColor=[UIColor whiteColor];	
			//輸出內容
			{
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r0 
								  sortString:titleupdownC1R0 ];				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r1 
								  sortString:titleupdownC1R1 ];
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR1 objectAtIndex:2] 
								   dataobjet:ob 
								  UILabel_cr:cell.c1r2 	
								  sortString:titleupdownC1R2 ];				
				
				cell.c1r1.hidden=NO;
				cell.c1r1.hidden=NO;
				cell.c1r2.hidden=NO;				
				
			}			
			
			
			
		}			
		
	}			
	//第3列欄位
	{
		//解析 有幾行				
		NSArray *csvLinesR2 = [[picka3 objectAtIndex:[[prefs objectForKey: @"tableR2" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
		
		 
		NSString *titleupdownC2R0=@"";
		NSString *titleupdownC2R1=@"";	
		NSString *titleupdownC2R2=@"";	
		 
		if (select_col_index==2) {
			switch (select_col_index_row-1) {
				case 0:{
					if (select_col_index_row_updwon==1) {
						titleupdownC2R0=@"▲";
					}
					else {
						titleupdownC2R0=@"▼";				
					}
					break;
				}
				case 1:{
					if (select_col_index_row_updwon==1) {
						titleupdownC2R1=@"▲";
					}
					else {
						titleupdownC2R1=@"▼";				
					}
					
					
					break;
				}	
				case 2:{
					if (select_col_index_row_updwon==1) {
						titleupdownC2R2=@"▲";
					}
					else {
						titleupdownC2R2=@"▼";				
					}
					break;
				}
					
				default:
					break;
			}		
		}
		
		
		
		
		if ([csvLinesR2 count]==1) {
			cell.c2r0.frame=CGRectMake(210, 10, c3Length, 40);
			cell.c2r0.font=[UIFont boldSystemFontOfSize:15];					
		    cell.c2r0.backgroundColor=[UIColor clearColor];
			cell.c2r0.textColor=[UIColor whiteColor];
			//輸出內容
			{ 
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r0 
								  sortString:titleupdownC2R0 ];
				cell.c2r1.hidden=NO;
				cell.c2r1.hidden=YES;
				cell.c2r2.hidden=YES;
				
			}				
			
		}
		else if ([csvLinesR2 count]==2) {
			cell.c2r0.frame=CGRectMake(210, 10, c3Length, 20);	
			cell.c2r1.frame=CGRectMake(210, 32, c3Length, 20);
			  
			cell.c2r0.font=[UIFont boldSystemFontOfSize:15];
			cell.c2r1.font=[UIFont boldSystemFontOfSize:15];
			
			
			cell.c2r0.backgroundColor=[UIColor clearColor];
			cell.c2r1.backgroundColor=[UIColor clearColor];
			
			cell.c2r0.textColor=[UIColor whiteColor];
			cell.c2r1.textColor=[UIColor yellowColor];	
			//輸出內容
			{
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r0  
								  sortString:titleupdownC2R0 ];				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r1 
								  sortString:titleupdownC2R1 ];				
				cell.c2r0.hidden=NO;
				cell.c2r1.hidden=NO;
				cell.c2r2.hidden=YES;
				
			}					
			
			
		}
		else if ([csvLinesR2 count]==3) {
			cell.c2r0.frame=CGRectMake(210, 0, c3Length,  20);	
			cell.c2r1.frame=CGRectMake(210, 20, c3Length, 20);
			cell.c2r2.frame=CGRectMake(210, 40, c3Length, 20);
			 
			cell.c2r0.font=[UIFont boldSystemFontOfSize:13];
			cell.c2r1.font=[UIFont boldSystemFontOfSize:13];
			cell.c2r2.font=[UIFont boldSystemFontOfSize:13];
			
			cell.c2r0.backgroundColor=[UIColor clearColor];
			cell.c2r1.backgroundColor=[UIColor clearColor];
			cell.c2r2.backgroundColor=[UIColor clearColor];
			
			cell.c2r0.textColor=[UIColor whiteColor];
			cell.c2r1.textColor=[UIColor yellowColor];				
			cell.c2r2.textColor=[UIColor whiteColor];
			
			//輸出內容
			{
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:0] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r0 
								  sortString:titleupdownC2R0 ];				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:1] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r1 
								  sortString:titleupdownC2R1 ];
				
				[self setStockTableQuoteCell:cell 
									 identfy:[csvLinesR2 objectAtIndex:2] 
								   dataobjet:ob 
								  UILabel_cr:cell.c2r2 	
								  sortString:titleupdownC2R2 ];				
				
				cell.c2r1.hidden=NO;
				cell.c2r1.hidden=NO;
				cell.c2r2.hidden=NO;				
				
			}				
			
			
			
		}			
		
	}		
	 
	 
	UIView *accessory = [cell accessoryView];
    
    
	if ([ob.activity  boolValue]) 
	{
        //報價
		if (![accessory isMemberOfClass:[UIActivityIndicatorView class]]) {
            accessory = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [(UIActivityIndicatorView *)accessory setHidesWhenStopped:NO];
            [cell setAccessoryView:accessory];
			[accessory release];
        }
        [(UIActivityIndicatorView *) accessory startAnimating];
    }
	else {
		
		//關閉指示器
		UIView *accessory = [cell accessoryView];
		if ([accessory isMemberOfClass:[UIActivityIndicatorView class]]) {
		    	[(UIActivityIndicatorView *) accessory stopAnimating];
			    [cell setAccessoryView:nil];
		   }	
		
				
	}
 
	 
     
	return cell;


}

/*
- (void)setupCell:(UITableViewCell *)cell forStockAtIndex:(NSUInteger )row {
	//[[cell detailTextLabel] setText: [download_data objectAtIndex: row]];
	
	UIView *accessory = [cell accessoryView];
	if (![accessory isMemberOfClass:[UIActivityIndicatorView class]]) {
            accessory = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
            [(UIActivityIndicatorView *)accessory setHidesWhenStopped:NO];
            [cell setAccessoryView:accessory];
            [accessory release];
	}
	[(UIActivityIndicatorView *) accessory startAnimating];
       
}
*/
 //設定表格高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //return [indexPath row] * 1.5; // your dynamic height...
       
    
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //開始MESA
             
                //標記:表格內展開出現日內走勢圖 展開高度            
                if ([expand_table_code indexOfObject:[NSString stringWithFormat:@"%i",indexPath.row]]!=NSNotFound ) {
                    return tablecell_high_zoom_out ;
                }
                else
                {
                    return 60;
                    
                }
                     
        }
        else{
            //開始LF
              return 60;            
        }
    }
    else{
       return 60;      
    }
    
    
    
    
    
  }
#pragma mark -
#pragma mark  Table的HeaderInSection 外觀與高度設定

//調整HeaderInSection 高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
	return TableHeigh;
}
//HeaderInSection 增加物件
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
	
  	UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(30.0, 0.0, 100.0, 200.0)] autorelease];
  	

	
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];        
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
             
            //section 底色設定
            customView.backgroundColor = [UIColor colorWithRed:1.0/255.0 green:14.0/255.0 blue:30.0/255.0 alpha:1.0];	
            //alpha 透明度 0.1:幾乎透明 1:不透明            
            
            
        }
        else{
            //開始LF
            //section 底色設定
            customView.backgroundColor = [UIColor colorWithRed:16.0/255.0 green:42.0/255.0 blue:64.0/255.0 alpha:1.0];	
            //alpha 透明度 0.1:幾乎透明 1:不透明           
            
            
            
        }
    }
    
    
    
    
    
    
    
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	 
	// 	
	UIButton * headerbuttonCol0 = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
 	headerbuttonCol0.frame = CGRectMake(25,  0, 85, 40);
	[headerbuttonCol0 addTarget:self action:@selector(sort_table_col0) forControlEvents:UIControlEventTouchUpInside];
	headerbuttonCol0.backgroundColor = [UIColor clearColor];
    //標記:判斷是MESA或LF    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            
            
            [headerbuttonCol0 setTitleColor: [UIColor colorWithRed:255.0/255.0 green:244.0/255.0 blue:125.0/255.0 alpha:1.0] forState:UIControlStateNormal];            
        }
        else{
            //開始LF
            
            
            [headerbuttonCol0 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];            
        }
    }
    
    
    
	NSArray *csvLinesR0 = [[picka1 objectAtIndex:[[prefs objectForKey: @"tableR0" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
	
	NSString *title0;
	NSString *titleupdownC0R0=@"  ";
	NSString *titleupdownC0R1=@"  ";	
	NSString *titleupdownC0R2=@"  ";	
	title0=@"";
	if (select_col_index==0) {
		switch (select_col_index_row-1) {
			case 0:{
				if (select_col_index_row_updwon==1) {
					titleupdownC0R0=@"▲";
				}
				else {
					titleupdownC0R0=@"▼";				
				}
				break;
			}
			case 1:{
				if (select_col_index_row_updwon==1) {
					titleupdownC0R1=@"▲";
				}
				else {
					titleupdownC0R1=@"▼";				
				}
				
				
				break;
			}	
			case 2:{
				if (select_col_index_row_updwon==1) {
					titleupdownC0R2=@"▲";
				}
				else {
					titleupdownC0R2=@"▼";				
				}
				break;
			}
				
			default:
				break;
		}		
	}
	if ([csvLinesR0 count]==3)	{
	   headerbuttonCol0.titleLabel.font= [UIFont boldSystemFontOfSize:12];	
	   title0=[title0 stringByAppendingFormat:@"%@%@\n%@%@\n%@%@",[csvLinesR0 objectAtIndex:0],titleupdownC0R0,[csvLinesR0 objectAtIndex:1],titleupdownC0R1,[csvLinesR0 objectAtIndex:2],titleupdownC0R2];
	}
	else if([csvLinesR0 count]==2){
		headerbuttonCol0.titleLabel.font= [UIFont boldSystemFontOfSize:13];
		title0=[title0 stringByAppendingFormat:@"%@%@\n%@%@",[csvLinesR0 objectAtIndex:0],titleupdownC0R0,[csvLinesR0 objectAtIndex:1],titleupdownC0R1];
	}
    else {
		headerbuttonCol0.titleLabel.font= [UIFont boldSystemFontOfSize:14];
		title0=[title0 stringByAppendingFormat:@"%@%@ ",[csvLinesR0 objectAtIndex:0],titleupdownC0R0];
		
	}
    
	headerbuttonCol0.titleLabel.lineBreakMode = UILineBreakModeWordWrap; //標頭換行用
	//headerbuttonCol0.titleLabel.textAlignment=UITextAlignmentRight;
	[headerbuttonCol0  setTitle:title0  forState:UIControlStateNormal  ];	
	[customView addSubview:headerbuttonCol0];		
	//c1==================
	
	UIButton * headerbuttonCol1 = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
 	headerbuttonCol1.frame = CGRectMake(110,  0, 100, 40);
	[headerbuttonCol1 addTarget:self action:@selector(sort_table_col1) forControlEvents:UIControlEventTouchUpInside];
	headerbuttonCol1.backgroundColor = [UIColor clearColor];
    //標記:判斷是MESA或LF    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            
            
            [headerbuttonCol1 setTitleColor: [UIColor colorWithRed:255.0/255.0 green:244.0/255.0 blue:125.0/255.0 alpha:1.0] forState:UIControlStateNormal];            
        }
        else{
            //開始LF
            
            
            [headerbuttonCol1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];            
        }
    }
	
	NSArray *csvLinesR1 = [[picka2 objectAtIndex:[[prefs objectForKey: @"tableR1" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
	NSString *title1;
	NSString *titleupdownC1R0=@"  ";
	NSString *titleupdownC1R1=@"  ";	
	NSString *titleupdownC1R2=@"  ";	
	title1=@"";
	if (select_col_index==1) {
		switch (select_col_index_row-1) {
			case 0:{
				if (select_col_index_row_updwon==1) {
					titleupdownC1R0=@"▲";
				}
				else {
					titleupdownC1R0=@"▼";				
				}
				break;
			}
			case 1:{
				if (select_col_index_row_updwon==1) {
					titleupdownC1R1=@"▲";
				}
				else {
					titleupdownC1R1=@"▼";				
				}
				
				
				break;
			}	
			case 2:{
				if (select_col_index_row_updwon==1) {
					titleupdownC1R2=@"▲";
				}
				else {
					titleupdownC1R2=@"▼";				
				}
				break;
			}
				
			default:
				break;
		}		
	}
	
	if ([csvLinesR1 count]==3)	{
		headerbuttonCol1.titleLabel.font= [UIFont boldSystemFontOfSize:12];	
		title1=[title1 stringByAppendingFormat:@"%@%@\n%@%@\n%@%@",[csvLinesR1 objectAtIndex:0],titleupdownC1R0,[csvLinesR1 objectAtIndex:1],titleupdownC1R1,[csvLinesR1 objectAtIndex:2],titleupdownC1R2];
	}
	else if([csvLinesR1 count]==2){
		headerbuttonCol1.titleLabel.font= [UIFont boldSystemFontOfSize:13];
		title1=[title1 stringByAppendingFormat:@"%@%@\n%@%@",[csvLinesR1 objectAtIndex:0],titleupdownC1R0,[csvLinesR1 objectAtIndex:1],titleupdownC1R1];
	}
    else {
		headerbuttonCol1.titleLabel.font= [UIFont boldSystemFontOfSize:14];
		title1=[title1 stringByAppendingFormat:@"%@%@ ",[csvLinesR1 objectAtIndex:0],titleupdownC1R0];
		
	}
	
	
	headerbuttonCol1.titleLabel.lineBreakMode = UILineBreakModeWordWrap; //標頭換行用
	//headerbuttonCol1.titleLabel.textAlignment=UITextAlignmentLeft;	
	[headerbuttonCol1  setTitle: title1 forState:UIControlStateNormal  ];	
	[customView addSubview:headerbuttonCol1];		
	
	
	UIButton * headerbuttonCol2 = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
 	headerbuttonCol2.frame = CGRectMake(210,  0, 85, 40);
	[headerbuttonCol2 addTarget:self action:@selector(sort_table_col2) forControlEvents:UIControlEventTouchUpInside];
	headerbuttonCol2.backgroundColor = [UIColor clearColor];
    //標記:判斷是MESA或LF    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            
            
            [headerbuttonCol2 setTitleColor: [UIColor colorWithRed:255.0/255.0 green:244.0/255.0 blue:125.0/255.0 alpha:1.0] forState:UIControlStateNormal];            
        }
        else{
            //開始LF
            
            
            [headerbuttonCol2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];            
        }
    }

    
    
    
	NSArray *csvLinesR2 = [[picka3 objectAtIndex:[[prefs objectForKey: @"tableR2" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
	 
	NSString *title2;
	NSString *titleupdownC2R0=@"  ";
	NSString *titleupdownC2R1=@"  ";	
	NSString *titleupdownC2R2=@"  ";	
	title2=@"";
	if (select_col_index==2) {
		switch (select_col_index_row-1) {
			case 0:{
				if (select_col_index_row_updwon==1) {
					titleupdownC2R0=@"▲";
				}
				else {
					titleupdownC2R0=@"▼";				
				}
				break;
			}
			case 1:{
				if (select_col_index_row_updwon==1) {
					titleupdownC2R1=@"▲";
				}
				else {
					titleupdownC2R1=@"▼";				
				}
				
				
				break;
			}	
			case 2:{
				if (select_col_index_row_updwon==1) {
					titleupdownC2R2=@"▲";
				}
				else {
					titleupdownC2R2=@"▼";				
				}
				break;
			}
				
			default:
				break;
		}		
	}

	if ([csvLinesR2 count]==3)	{
		headerbuttonCol2.titleLabel.font= [UIFont boldSystemFontOfSize:12];	
		title2=[title2 stringByAppendingFormat:@"%@%@\n%@%@\n%@%@",[csvLinesR2 objectAtIndex:0],titleupdownC2R0,[csvLinesR2 objectAtIndex:1],titleupdownC2R1,[csvLinesR2 objectAtIndex:2],titleupdownC2R2];
	}
	else if([csvLinesR2 count]==2){
		headerbuttonCol2.titleLabel.font= [UIFont boldSystemFontOfSize:13];
		title2=[title2 stringByAppendingFormat:@"%@%@\n%@%@",[csvLinesR2 objectAtIndex:0],titleupdownC2R0,[csvLinesR2 objectAtIndex:1],titleupdownC2R1];
	}
    else {
		headerbuttonCol2.titleLabel.font= [UIFont boldSystemFontOfSize:14];
		title2=[title2 stringByAppendingFormat:@"%@%@ ",[csvLinesR2 objectAtIndex:0],titleupdownC2R0];
		
	}
	
	
	headerbuttonCol2.titleLabel.lineBreakMode = UILineBreakModeWordWrap; //標頭換行用
	[headerbuttonCol2  setTitle:title2 forState:UIControlStateNormal  ];	
	[customView addSubview:headerbuttonCol2];		
	
	
	
	
	
	
	
	/*
	
	UILabel * headerLabel_code = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_code.backgroundColor = [UIColor clearColor];
	headerLabel_code.opaque = NO;
	headerLabel_code.textColor = [UIColor whiteColor];
	headerLabel_code.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_code.frame = CGRectMake(10,-10, 100.0, 30.0);
	headerLabel_code.textAlignment = UITextAlignmentLeft;
	headerLabel_code.text = [NSString stringWithString:NSLocalizedString(@"Code",@"Code") ];
	headerLabel_code.alpha=0.5;	
	[customView addSubview:headerLabel_code];
	
	UILabel * headerLabel_name = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_name.backgroundColor = [UIColor clearColor];
	headerLabel_name.opaque = NO;
	headerLabel_name.textColor = [UIColor whiteColor];
	headerLabel_name.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_name.frame = CGRectMake(10,5, 100.0, 30.0);
	headerLabel_name.textAlignment = UITextAlignmentLeft;
	headerLabel_name.text = [NSString stringWithString:NSLocalizedString(@"Name",@"Name")];
	headerLabel_name.alpha=0.5;	
	[customView addSubview:headerLabel_name];	
	 
	UILabel * headerLabel_price = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_price.backgroundColor = [UIColor clearColor];
	headerLabel_price.opaque = NO;
	headerLabel_price.textColor = [UIColor whiteColor];
	headerLabel_price.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_price.frame = CGRectMake(130,-10, 100.0, 30.0);
	headerLabel_price.textAlignment = UITextAlignmentLeft;
	headerLabel_price.text = [NSString stringWithString:NSLocalizedString(@"Price",@"Price")];
	headerLabel_price.alpha=0.5;	
	[customView addSubview:headerLabel_price];			  
	
	UILabel * headerLabel_date = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_date.backgroundColor = [UIColor clearColor];
	headerLabel_date.opaque = NO;
	headerLabel_date.textColor = [UIColor whiteColor];
	headerLabel_date.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_date.frame = CGRectMake(130,5, 100.0, 30.0);
	headerLabel_date.textAlignment = UITextAlignmentLeft;
	headerLabel_date.text = [NSString stringWithString:NSLocalizedString(@"Date",@"Date")];
	headerLabel_date.alpha=0.5;	
	[customView addSubview:headerLabel_date];		  
	
	UILabel * headerLabel_time = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_time.backgroundColor = [UIColor clearColor];
	headerLabel_time.opaque = NO;
	headerLabel_time.textColor = [UIColor whiteColor];
	headerLabel_time.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_time.frame = CGRectMake(185,5, 100.0, 30.0);
	headerLabel_time.textAlignment = UITextAlignmentLeft;
	headerLabel_time.text = [NSString stringWithString:NSLocalizedString(@"Time",@"Time")];
	headerLabel_time.alpha=0.5;	
	[customView addSubview:headerLabel_time];				  
	
	UILabel * headerLabel_change = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_change.backgroundColor = [UIColor clearColor];
	headerLabel_change.opaque = NO;
	headerLabel_change.textColor = [UIColor whiteColor];
	headerLabel_change.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_change.frame = CGRectMake(235,-10, 100.0, 30.0);
	headerLabel_change.textAlignment = UITextAlignmentLeft;
	headerLabel_change.text = [NSString stringWithString:NSLocalizedString(@"Change",@"Change")];
	headerLabel_change.alpha=0.5;	
	[customView addSubview:headerLabel_change];				  
	
	UILabel * headerLabel_rchange = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
	headerLabel_rchange.backgroundColor = [UIColor clearColor];
	headerLabel_rchange.opaque = NO;
	headerLabel_rchange.textColor = [UIColor whiteColor];
	headerLabel_rchange.font = [UIFont boldSystemFontOfSize:13];
	headerLabel_rchange.frame = CGRectMake(235,5, 100.0, 30.0);
	headerLabel_rchange.textAlignment = UITextAlignmentLeft;
	headerLabel_rchange.text = [NSString stringWithString:NSLocalizedString(@"Change %",@"Change %")];
	headerLabel_rchange.alpha=0.5;	
	[customView addSubview:headerLabel_rchange];		  
	
	*/
	//顯式報價欄位設定
	UIButton *gainlossshowhide = [UIButton buttonWithType:UIButtonTypeInfoLight];
	gainlossshowhide.frame= CGRectMake(0,10, 20.0, 20.0);
	[gainlossshowhide addTarget:self action:@selector(showSetup) forControlEvents:UIControlEventTouchUpInside];	
	[customView addSubview:gainlossshowhide];		  
	
	
	
	/*
	 //取出設定檔資料 是否進行最佳化
	 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	 [prefs  boolForKey:@"isActiveOptimize" ];
	 if ((BOOL)[prefs  boolForKey:@"isActiveOptimize" ]==YES) {
	 
	 UIButton * headerbutton = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
	 CGRect buttonframe=headerbutton.frame;
	 buttonframe.origin.x=100;
	 buttonframe.origin.y=0;
	 buttonframe.size.height=TableHeigh;
	 buttonframe.size.width=60;
	 headerbutton.frame = buttonframe;
	 
	 [headerbutton addTarget:self action:@selector(refreshALL:) forControlEvents:UIControlEventTouchUpInside];
	 //進行排序
	 //[headerbutton addTarget:self action:@selector(sort_table) forControlEvents:UIControlEventTouchUpInside];
	 
	 headerbutton.backgroundColor = [UIColor redColor];
	 headerbutton.titleLabel.font= [UIFont boldSystemFontOfSize:10];
	 [headerbutton  setTitle:@"進行最佳化" forState:UIControlStateNormal  ];	
	 
	 [customView addSubview:headerbutton];			  
	 
	 }
	 */
	
	
	
	
	
	UIButton * refreshbutton = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
	CGRect fbuttonframe=refreshbutton.frame;
	fbuttonframe.origin.x=300;
	fbuttonframe.origin.y=10;
	fbuttonframe.size.height=20;
	fbuttonframe.size.width=20;
	refreshbutton.frame = fbuttonframe;
	[refreshbutton  setImage:  [UIImage imageNamed:@"refresh.png"]  forState:UIControlStateNormal];
	[refreshbutton addTarget:self action:@selector(buttont_refresh:) forControlEvents:UIControlEventTouchUpInside];
	[customView addSubview:refreshbutton ];			 
	
	/*
	 progressView=[[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
	 [progressView setBackgroundColor:[UIColor clearColor]];
	 progressView.frame=CGRectMake(30.0, 45.0, 150.0, 20.0);
	 [customView addSubview:progressView];
	 */  
	
	 
	
	
	return customView;
}

#pragma mark -
#pragma mark  Table的HeaderInSection 處理方法與屬性

//啓動所有物件回補歷史資料
-(void)refreshALL:sender{
	NSLog(@"refresh=%@",self.title);
	if (isInOptimize==NO) {
		progresscount=[download_data_obj count];
		isInOptimize=YES;
		amountDone  = 1.0f;
	}
	else {
		amountDone += 1.0f;		
	}

	
	//使table cell 上出現進度指示器 強迫所有的都顯示進度
	if([download_data_obj count]>0) {
		DataObject *ob;
		ob=[download_data_obj objectAtIndex:0];
		ob.activity= [NSNumber numberWithBool:YES];
		 //重刷表格資料
		[[self tableView] reloadData];			//執行進度顯示器	
		// calcuate_stop=NO;
        [self presentSheet];
         NSLog(@"[self presentSheet] 2");        
		[self incrementBara:ob.symbol];		
	}   
 
	//開始物件歷史資料全部下載
	
	if ([download_data_obj count]>0) {
		
		DataObject *dob;
		
		dob=[download_data_obj objectAtIndex:0];	
		
		dob.dwm=Gdwm;
		//; //交易系統最佳化時改變次處參數可以修正日週月的其間最佳化參數
		NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
		//如果是要進行最佳化 則檢查是要最佳化日週月
		if ([prefs  boolForKey:@"isActiveOptimize" ]==YES) {
			
			//將目前進行最佳化的群組名子寫入
			[prefs setObject:self.title forKey:@"now_Optimize_group_name"];
			[prefs synchronize];			
			
			
			switch ([prefs integerForKey:@"isActiveOptimize_dwm" ]) {
				case 0:{
					 
					dob.dwm=@"d";					
					break;
				}
				case 1:{
					 
					dob.dwm=@"w";
					break;
				}
				case 2:{
					dob.dwm=@"m";
					break;
				}
				default:
					break;
			}			
			
			
		}	
		
		
		dob.delgete=self;	
		[dob getYahooHistroryDatagraphindex:0 
								writetofile:YES 
								  drawChart:NO 
				 closeCellActivityIndicator:YES
						   isuseNavagarator:NO 
					   isresetGraphLocation:NO 
								 isOptimize:YES
					isCaluateTableIndicator:NO]; //進行最佳化	
	}   
	else {
		//將進度畫面銷除
		[self.baseSheet dismissWithClickedButtonIndex:0 animated:YES]; 		
		
	}

	
	//======================
	NSLog(@"refresh3");
}
-(void)buttont_refresh:sender{
	
	/*此段程式重要 不可以刪除 很重要的範例
	//功能選項畫面啓動
	CustomUIActionSheetViewControllerNxib * ee;
	ee=[[CustomUIActionSheetViewControllerNxib alloc] init];
	[navdelegete.view addSubview:ee.view];
	[ee viewWillAppear:NO];
	ee.delgete=self;	
    //=============
	*/ 
	
	
	//回補報價物件啓動
	if (isDownloadQuoteNow==NO) {
		isDownloadQuoteNow=YES;
		
		isfirstQuote=YES;
        calcuate_stop=NO;        
		[self refeshTableQuote];			
		
	} 
	
 
	
 	 
	
	
	
	//==============
}

#pragma mark -
#pragma mark  CustomUIActionDelgete

//當設定表格欄位結束時的方法
-(void)button_CustomUIActionDelgeteNxib{
	  
	//回補報價物件啓動
	
	isfirstQuote=YES;
	[self refeshTableQuote]; 
	//==============	
	
	
}
#pragma mark -
#pragma mark  排序報表
-(void)sort_table_col0{
	select_col_index=0;
	[self sort_table];
}
-(void)sort_table_col1{
	select_col_index=1;
	[self sort_table];	
	
}
-(void)sort_table_col2{
    select_col_index=2;
	[self sort_table];	
}

#pragma mark -
#pragma mark  清除日內線記憶體
-(void)Clean_memory_intraday_data{
    //清除日內線資料
    if (expand_table_code!=nil) {
        if ([expand_table_code count]>0) {
            /*
             [expand_table_code release]; //記錄有哪些表格是展開的
             expand_table_code=nil;
             */
            [expand_table_code removeAllObjects];
            
            
            
        }        
        
    }
    if (intraday_data!=nil) {
        if ([intraday_data_code count]>0) {
            //標記:日內走勢圖記憶體宣告實體與消滅 消滅
            
            [intraday_data_code removeAllObjects]; //暫存日內資料
            [intraday_data removeAllObjects]; //暫存日內資料 
            [intraday_data_x_time removeAllObjects]; //暫存日內資料            
            
            [intraday_graph_x_length removeAllObjects];// 日內走勢圖的x軸 長度    
            [intraday_graph_x_high removeAllObjects];// 日內走勢圖的x軸 最高價    
            [intraday_graph_x_low removeAllObjects];// 日內走勢圖的x軸 最低價             
            
            [ intraday_graph_volume_high removeAllObjects];// 日內走勢圖的x軸 最高量    
            [intraday_graph_volume_low removeAllObjects];// 日內走勢圖的x軸 最低量
            [intraday_graph_lastdayClose removeAllObjects];//前一日收盤價  
            
            [intraday_graph_selected_right removeAllObjects];//日內走勢圖的x軸 右邊
            [intraday_graph_selected_left removeAllObjects]; //日內走勢圖的x軸 左邊             
        }   
    }
}
#pragma mark -
#pragma mark  Yahoo ticker與Google ticker轉換
//標記:Yahoo ticker與Google ticker轉換 StockTableQuote.m

//從yahoo 轉成 google
-(NSString *)TickerConvert_yahoo_google:(NSString *)yahoo_ticker{
    if (yahoo_ticker!=nil) {
        
        NSArray * code_array=[yahoo_ticker componentsSeparatedByString:@"."];        
       
        //標記:Add Target need Program
        
        if ([code_array count]==1) {
        //美國    
            return yahoo_ticker;
        }
        else if ([code_array count]==2) {
        //非美國
            //GOOGLE
            if ([[code_array objectAtIndex:1] isEqualToString:@"HK"]) {
                //香港
                return [NSString stringWithFormat:@"%@:%@",@"HKG",[code_array objectAtIndex:0]];                
                
            }
            else if ([[code_array objectAtIndex:1] isEqualToString:@"TW"] || [[code_array objectAtIndex:1] isEqualToString:@"TWO"] ) {
                //台灣                
                return [NSString stringWithFormat:@"%@:%@",@"TPE",[code_array objectAtIndex:0]];                
                
            }    
            else if ([[code_array objectAtIndex:1] isEqualToString:@"AX"]) {
              //澳洲
                return [NSString stringWithFormat:@"%@:%@",@"ASX",[code_array objectAtIndex:0]];                
                
            }
            else if ([[code_array objectAtIndex:1] isEqualToString:@"SS"] ) {
                //中國 上海               
                return [NSString stringWithFormat:@"%@:%@",@"SHA",[code_array objectAtIndex:0]];                
                
            }                
            else if ([[code_array objectAtIndex:1] isEqualToString:@"SZ"] ) {
                //中國 深圳                
                return [NSString stringWithFormat:@"%@:%@",@"SHE",[code_array objectAtIndex:0]];                
                
            }  
            else if ([[code_array objectAtIndex:1] isEqualToString:@"TO"]  ) {
                //加拿大                
                return [NSString stringWithFormat:@"%@:%@",@"TSE",[code_array objectAtIndex:0]];                
                
            } 
            else if ([[code_array objectAtIndex:1] isEqualToString:@"V"]  ) {
                //加拿大                
                return [NSString stringWithFormat:@"%@:%@",@"CVE",[code_array objectAtIndex:0]];                
                
            } 
             
            else if ([[code_array objectAtIndex:1] isEqualToString:@"NS"] ) {
                //印度               
                return [NSString stringWithFormat:@"%@:%@",@"NSE",[code_array objectAtIndex:0]];                
                
            }                
            else if ([[code_array objectAtIndex:1] isEqualToString:@"BO"] ) {
                //印度                
                return [NSString stringWithFormat:@"%@:%@",@"NSE",[code_array objectAtIndex:0]];                
                //雖然雅虎用BO 但是google
            }          
            else if ([[code_array objectAtIndex:1] isEqualToString:@"BE"] || [[code_array objectAtIndex:1] isEqualToString:@"BM"]  || [[code_array objectAtIndex:1] isEqualToString:@"DU"] || [[code_array objectAtIndex:1] isEqualToString:@"F"]  || [[code_array objectAtIndex:1] isEqualToString:@"HM"] || [[code_array objectAtIndex:1] isEqualToString:@"HA"] || [[code_array objectAtIndex:1] isEqualToString:@"MU"] || [[code_array objectAtIndex:1] isEqualToString:@"SG"] || [[code_array objectAtIndex:1] isEqualToString:@"DE"] ) {
                //德國  目前看來僅有 Deutsche Börse XETRA  電子交易所可以用         
                return [NSString stringWithFormat:@"%@:%@",@"ETR",[code_array objectAtIndex:0]];                
                 
            } 
            else if ([[code_array objectAtIndex:1] isEqualToString:@"KS"] ) {
                //韓國                
                return [NSString stringWithFormat:@"%@:%@",@"SEO",[code_array objectAtIndex:0]];                
                 
            }              
            else if ([[code_array objectAtIndex:1] isEqualToString:@"KQ"] ) {
                //韓國                
                return [NSString stringWithFormat:@"%@:%@",@"KDQ",[code_array objectAtIndex:0]];                
                
            }  
            else if ([[code_array objectAtIndex:1] isEqualToString:@"NZ"] ) {
                //紐西蘭                
                return [NSString stringWithFormat:@"%@:%@",@"NZE",[code_array objectAtIndex:0]];                
                
            }               
            else if ([[code_array objectAtIndex:1] isEqualToString:@"PA"] || [[code_array objectAtIndex:1] isEqualToString:@"NX"] ) {
                //法國                
                return [NSString stringWithFormat:@"%@:%@",@"EPA",[code_array objectAtIndex:0]];                
                
            }               
            else if ([[code_array objectAtIndex:1] isEqualToString:@"SA"] ) {
                //巴西                
                return [NSString stringWithFormat:@"%@:%@",@"SAO",[code_array objectAtIndex:0]];                
                
            }              
            else if ([[code_array objectAtIndex:1] isEqualToString:@"MX"] ) {
                //墨西哥  尚未有報價              
                return [NSString stringWithFormat:@"%@:%@",@"MXK",[code_array objectAtIndex:0]];                
                
            }  
            else if ([[code_array objectAtIndex:1] isEqualToString:@"SI"] ) {
                //新加坡  尚未有報價            
                return [NSString stringWithFormat:@"%@:%@",@"SIN",[code_array objectAtIndex:0]];                
                
            }             
            else if ([[code_array objectAtIndex:1] isEqualToString:@"L"] ) {
                //英國  有報價         
                return [NSString stringWithFormat:@"%@:%@",@"LON",[code_array objectAtIndex:0]];                
                
            }                 
            
            else{
                return [code_array objectAtIndex:0];
            }
          
        
        
        }
        else{
         return @"";
        
        }
    }
    else{
    
        return  @"";
    
    }
}
//從google 轉成 yahoo
-(NSString *)TickerConvert_google_yahoo:(NSString *)google_ticker{
    for (NSString *codd in data_code  ) {
       //因為是比較前面的字串是不是符合前面幾個字  
        if ([codd hasPrefix:google_ticker]) {
            return codd;
        }
        
        
    }
    
    return @"";
}


#pragma mark -
#pragma mark  利用網路物件來下載股價報價資料
-(void)refeshTableQuote{
	acv.hidden=NO;    
    if (refresh_quote_time!=nil) {
        [refresh_quote_time release];
    } 
    
    refresh_quote_time=[[NSDate date] retain];
   	 
	NSLog(@"refeshTableQuote_start");
   
       
    
    //標記:tabBarController 暫停使用 (暫停使用  refeshTableQuote)   
    [(AppDelegate * )AppleDeglate Set_tabBarController_DisEnable];
   
   
           
    
    NSLog(@"refeshTableQuote:data_code count=%i",[data_code count]);
    
    
    
    if ([data_code count]==0) {
        //表示無自選股  
        acv.hidden=YES;
        return;
    }
    else{
       //表示有自選股 所以要先將回到前一頁的按鈕暫時隱藏 
        self.navigationItem.hidesBackButton=YES;     
    }
    
    
	//yahoo 可以一次下載最大數
   // int max_yahoo_download;
	//max_yahoo_download=200; 	
	
    //網址設定
    NSString *identify;
	NSString *urls_yahoo =  @"http://download.finance.yahoo.com/d/quotes.csv?s=" ;
    NSString *urls_google =  @"http://www.google.com/finance/info?infotype=infoquoteall&q=" ;
    
    
	//如果是第一次啟動下載報價資料
    if (isfirstQuote==YES) {
		[temp_data_code release];
        temp_data_code=[data_code mutableCopy]; //一筆將要下載的資料轉入到暫存區
       
    }
	 
    //後面此段主要是用來排除如果自選股只有一檔時的錯誤
	BOOL ifcount1;
    if ([temp_data_code count]==1 && isfirstQuote==YES) {
        ifcount1=YES;
    }
    else{
        ifcount1=NO;
    }
	
	for (int i=0; i<[temp_data_code count] && i<max_download; i++) {
	    NSLog(@"i=%i temp_data_code count=%i " ,i,[temp_data_code count]);
        //Yahoo產生要下載的代碼字串
		urls_yahoo=[urls_yahoo stringByAppendingString:  [temp_data_code objectAtIndex:i]   ];
		urls_yahoo=[urls_yahoo stringByAppendingString:@"+"];
		//Google產生要下載的代碼字串 
        urls_google=[urls_google stringByAppendingString:  [self TickerConvert_yahoo_google: [temp_data_code objectAtIndex:i] ]  ];
		urls_google=[urls_google stringByAppendingString:@","];           
       
        [temp_data_code removeObjectAtIndex:i];  //從暫存區扣除掉 
		
	}
  
    
    //檢查暫存區目前的使用量,將使用量結果回報至identify 
 
    
    if (ifcount1==YES) {
        identify=@"refeshQuoteObject_start";
        isfirstQuote=NO;
    }
    else{
        
        
        if ([temp_data_code count]>0) {
            //如果暫存區還有剩下
            if (isfirstQuote==YES) {
                identify=@"refeshQuoteObject_start";
                isfirstQuote=NO;
            }
            else {
                identify=@"refeshQuoteObject_repeat";
            }
            
        }
        else {
            //暫存都用完資料
            identify=@"refeshQuoteObject_end";
        }    
    }
    
  
	//Yahoo最後一段url	
	urls_yahoo=[urls_yahoo stringByAppendingString:@"&f=sl1d1t1c1p2ohgve7r7ohg&e=.csv"];
	NSLog(@"urls_Yahoo=%@",urls_yahoo);
	urls_yahoo = [urls_yahoo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];	  
    //Google最後一段url	
	 
	// NSLog(@"urls_Google=%@",urls_google);
	urls_google = [urls_google stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];	  
   
    /*
    //暫時取出google
    NSURL *  urla;
    urla = [NSURL URLWithString:urls_google];    
    
    NSError * errorq = nil;
    NSString * download_string;
    download_string=[NSString stringWithContentsOfURL:urla encoding:NSUTF8StringEncoding error:&errorq];
    
    
    //去除無用的字串 '//'
    NSString *string_for_jsonvalue= [download_string stringByReplacingOccurrencesOfString: @"//" withString:@"" ];
    
    //將字串的每個elements 分解出來      
    NSArray *jsonvalue_elements = [string_for_jsonvalue JSONValue];
    
    for (NSDictionary *s in jsonvalue_elements ) {
        NSLog(@"s=%@",s);
        //取出每個objects 的值
        
        NSLog(@"yahoo symbol= %@" , [self TickerConvert_google_yahoo: [s objectForKey:@"t"] ] );            
        NSLog(@"l=%@",[s objectForKey:@"l"]  );   //收盤價
        NSLog(@"lt=%@",[s objectForKey:@"lt"]  );            
        NSLog(@"ltt=%@",[s objectForKey:@"ltt"]  );  
        NSLog(@"c=%@",[s objectForKey:@"c"]  );//漲跌          
        NSLog(@"c=%@",[s objectForKey:@"cp"]  );  //漲跌福
        NSLog(@"op=%@",[s objectForKey:@"op"]  );  //oplen        
        NSLog(@"hi=%@",[s objectForKey:@"hi"]  );  //high  
        NSLog(@"lo=%@",[s objectForKey:@"lo"]  );  //lo
        NSLog(@"vo=%@", [s objectForKey:@"vo"]   );  //volume M百萬 B十億
        NSLog(@"eps=%@",[s objectForKey:@"eps"]  );  //volume         
        
    }            
    
    //暫時上 尚未完成 最後一段 示希望可以將google資料轉成line方式來處理
    */
    
	//利用網路下載物件來下載資料
	if (downloadobject.loadingData==NO) {
		
        //標記:Yahoo與Google 資料選擇修改位置 報價表-網址 
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
        if ([[prefs objectForKey:@"isYahoo"] boolValue]==YES) {
           //Yahoo
            //[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	
            //acv.hidden=NO;            
            
            
            [downloadobject release];
            downloadobject=[[DownloadData alloc]init];
            downloadobject.delgete=self;
            [downloadobject StartDownload:urls_yahoo  
                               identifier:identify];
            
            
        }        
        else{
            //Google
            //[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	
            //acv.hidden=NO;            
            
            
            [downloadobject release];
            downloadobject=[[DownloadData alloc]init];
            downloadobject.delgete=self;
            [downloadobject StartDownload:urls_google 
                               identifier:identify];
            
                         
        }
        
       
		 
	}
    
        
  	
	
    
    NSLog(@"refeshTableQuote_end");
}
#pragma mark -
#pragma mark 時間時區調整 英文字母的月份轉為數字
/* 重點與觀念
 1.NSdate 基本上是一個從1970 年起算到某一時間點的秒數 所以不會有時區 與日光時間的問題
 2.時區轉換要使用 [NSTimeZone timeZoneWithName:@"America/New_York"];  不要使用[ NSTimeZone  timeZoneWithAbbreviation:@"EDT"]; 
 3.NSTimeZone 的日光節約時間是可以選定哪一個日期後來判斷是不是此日期為日光節約時間
 
 
*/
//標記:時區轉換 從國家碼轉為地區碼

-(NSString *)Symbol_converTo_timeZoneWithName:(NSString*) symbol{
    symbol=[symbol uppercaseString];
    
    NSArray *code_array;
    code_array=[symbol componentsSeparatedByString:@"."];
    //標記:Add Target need Program 時區轉換
    
    
    if ([code_array count]==2) {
       //非美國國家交易所
        if ([[code_array objectAtIndex:1] isEqualToString:@"HK"]) {
            //香港
            return @"Asia/Hong_Kong";
        }
        else if ([[code_array objectAtIndex:1] isEqualToString:@"TW"] || [[code_array objectAtIndex:1] isEqualToString:@"TWO"]){
            //台灣
            return @"Asia/Taipei";
        }   
        else if ([[code_array objectAtIndex:1] isEqualToString:@"AX"]  ){
            //澳洲
            return @"Australia/Sydney";
        } 
        else if ([[code_array objectAtIndex:1] isEqualToString:@"SS"] || [[code_array objectAtIndex:1] isEqualToString:@"SZ"]){
            //中國
            return @"Asia/Shanghai";
        }  
        else if ([[code_array objectAtIndex:1] isEqualToString:@"TO"] || [[code_array objectAtIndex:1] isEqualToString:@"V"]){
            //加拿大
            return @"America/Toronto";
        } 
        else if ([[code_array objectAtIndex:1] isEqualToString:@"BE"] || [[code_array objectAtIndex:1] isEqualToString:@"BM"]  || [[code_array objectAtIndex:1] isEqualToString:@"DU"] || [[code_array objectAtIndex:1] isEqualToString:@"F"]  || [[code_array objectAtIndex:1] isEqualToString:@"HM"] || [[code_array objectAtIndex:1] isEqualToString:@"HA"] || [[code_array objectAtIndex:1] isEqualToString:@"MU"] || [[code_array objectAtIndex:1] isEqualToString:@"SG"] || [[code_array objectAtIndex:1] isEqualToString:@"DE"]  ){
            //德國
            return @"Europe/Berlin";
        }          
        else if ([[code_array objectAtIndex:1] isEqualToString:@"BO"] || [[code_array objectAtIndex:1] isEqualToString:@"NS"]){
            //印度
            return @"Asia/Kolkata";
        }  
        else if ([[code_array objectAtIndex:1] isEqualToString:@"KS"] || [[code_array objectAtIndex:1] isEqualToString:@"KQ"]){
            //韓國
            return @"Asia/Seoul";
        }
        else if ([[code_array objectAtIndex:1] isEqualToString:@"MI"]  ){
            //義大利
            return @"Europe/Rome";
        } 
        else if ([[code_array objectAtIndex:1] isEqualToString:@"NZ"]  ){
            //紐西蘭
            return @"Pacific/Auckland";
        } 
        else if ([[code_array objectAtIndex:1] isEqualToString:@"PA"] || [[code_array objectAtIndex:1] isEqualToString:@"NX"] ){
            //法國
            return @"Europe/Paris";
        }           
        else if ([[code_array objectAtIndex:1] isEqualToString:@"SA"]  ){
            //巴西
            return @"America/Sao_Paulo";
        }         
        else if ([[code_array objectAtIndex:1] isEqualToString:@"MX"]  ){
            //墨西哥
            return @"America/Mexico_City";
        }           
        else if ([[code_array objectAtIndex:1] isEqualToString:@"SI"]  ){
            //新加坡
            return @"Asia/Singapore";
        }          
        else if ([[code_array objectAtIndex:1] isEqualToString:@"L"]  ){
            //英國
            return @"Europe/London";
        }          
        else{
            //如果 都沒有找到設定 就設定為 美國國家交易所
            return @"America/New_York";            
            
        }
    }
    else{
       //美國國家交易所
       return @"America/New_York";
    }
   
}

//標記:將三個英文字母的月份轉為數字
-(int)MMM_MonthConvertToInterger:(NSString *)mmm{
    NSString *MMMs;
    MMMs=[mmm uppercaseString];
    if ([MMMs isEqualToString:[@"Jan" uppercaseString] ]) {
        return 1;
    }
    else if ([MMMs isEqualToString:[@"Feb" uppercaseString] ]) {
        return 2;
    }  
    else if ([MMMs isEqualToString:[@"Mar" uppercaseString] ]) {
        return 3;
    }  
    else if ([MMMs isEqualToString:[@"Apr" uppercaseString] ]) {
        return 4;
    }  
    else if ([MMMs isEqualToString:[@"May" uppercaseString] ]) {
        return 5;
    }  
    else if ([MMMs isEqualToString:[@"Jun" uppercaseString] ]) {
        return 6;
    }  
    else if ([MMMs isEqualToString:[@"Jul" uppercaseString] ]) {
        return 7;
    } 
    else if ([MMMs isEqualToString:[@"Aug" uppercaseString] ]) {
        return 8;
    }  
    else if ([MMMs isEqualToString:[@"Sep" uppercaseString] ]) {
        return 9;
    }  
    else if ([MMMs isEqualToString:[@"Oct" uppercaseString] ]) {
        return 10;
    }      
    else if ([MMMs isEqualToString:[@"Nov" uppercaseString] ]) {
        return 11;
    }  
    else if ([MMMs isEqualToString:[@"Dec" uppercaseString] ]) {
        return 12;
    }  
    else{
        return 0;
    
    }

}


#pragma mark -
#pragma mark 判斷是否為數字
//標記:判斷是否為數字
//判断是否为整形：

- (BOOL)isPureInt:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string]; 
    int val; 
    return[scan scanInt:&val] && [scan isAtEnd];
}
//判断是否为浮点形：
- (BOOL)isPureFloat:(NSString*)string{
    NSScanner* scan = [NSScanner scannerWithString:string]; 
    float val; 
    return[scan scanFloat:&val] && [scan isAtEnd];
}


#pragma mark -
#pragma mark 網路下載資料物件的  delegate 方法(用在報價資料的回補)

//下載資料完成
-(void)Download_Finish:(NSString *)datas Oidentifier:(NSString*)OutIdentifier{
     //NSLog(@"table quote_datas=%@",datas);
    
    
	//利用網路下載物件來下載資料	
	//下載資料完畢之後的啓動方法
    
    BOOL isCalcuateTableIndic=NO;
    
    if ([OutIdentifier hasPrefix:@"refeshQuoteObject"]) {
		//表示下載股價報價資料成功
		//記得要初始化實體化步驟
        
		if ([OutIdentifier isEqualToString:@"refeshQuoteObject_start"]) {
			//第ㄧ次啓動下載所以清空
			 
            if ( download_data_obj !=nil) {
               
                int ir;
                ir=[download_data_obj retainCount];
                for (int i=0; i<ir; i++) {
                    [download_data release];
                    [download_data_obj release];  
                }
                             
                
            }
                 
             
			download_data = [[NSMutableArray alloc] init];
			download_data_obj = [[NSMutableArray alloc] init];			
			 
		}
		//下載資料分析與處理
		NSArray *csvLines = [datas  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
        
       
        
		NSString *line  ;
        NSArray *pdata ;
        
        //標記:Yahoo與Google 資料選擇修改位置 報價表-下載資料處理 
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
        if ([[prefs objectForKey:@"isYahoo"] boolValue]==YES) {
        //yahoo    
             
            for (NSUInteger i=0; i<[csvLines count]-1; i++) {
                
                line = (NSString *)[csvLines objectAtIndex:i];
			                    
                 if([download_data indexOfObject:line]==2147483647)
			
                {
                    
                    
                //判斷字串是否為空白字串
			    if([line length]>0){
                    
                   
                    if (pdata!=nil) {
                        // NSLog(@"1pdada retain count=%i",[pdata retainCount]);
                    }
                    
                    
                    pdata = [line componentsSeparatedByString:@","]   ;   
                    [download_data addObject: line];  
                     
                    if ([pdata count]>2) {
						NSString *code;
						NSString *lastprice;
						NSString *open;
						NSString *high;
						NSString *low;
						
						NSString *tradedate;
						NSString *tradetime;
						NSString *updown;
						NSString *updownPercent;
						NSNumber *activity;
						NSString *his;
						NSString *volume_yahoo;
						NSString *EPS_Estimate_Current_Year_yahoo;
						NSString *Price_EPS_Estimate_Next_Year_yahoo;
						 					
						NSString *id_class;
						//NSNumber *num_updown;
						NSNumber *num_updownpercent;
						
                        
                        code= [[pdata objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ]   ;	
                        //code=[[NSString alloc] initWithString:code];
                        
                        lastprice =[pdata objectAtIndex:1] ;
                        tradedate=  [[pdata objectAtIndex:2]  stringByReplacingOccurrencesOfString:@"\"" withString:@""] ;
                        tradetime=  [[pdata objectAtIndex:3] stringByReplacingOccurrencesOfString:@"\"" withString:@""] ;	 
                        
                        NSLog(@"orange-tradedate=%@",tradedate);
                        NSLog(@"orange-tradetime=%@",tradetime);
                        
                        
                        int year,month,day,hour,minute;
                        //取出年月日
                        {
                            NSArray *date_array;
                            date_array=[tradedate componentsSeparatedByString:@"/"];
                            if ([date_array count]==3) {
                                year=[[date_array objectAtIndex:2] intValue];
                                month=[[date_array objectAtIndex:0] intValue];
                                day=[[date_array objectAtIndex:1] intValue];                            
                            }
                            else{
                                //年月日資料有問題
                                year=0;
                                month=0;
                                day=0;
                            }
                            
                            if ([[tradetime lowercaseString] hasSuffix:@"am"] ) {
                                   
                                tradetime=[tradetime stringByReplacingOccurrencesOfString:@"am" withString:@""] ;
                                NSArray *time_array;
                                time_array=[tradetime componentsSeparatedByString:@":"];
                                if ([time_array count]==2) {
                                    hour=[[time_array objectAtIndex:0] intValue];
                                    minute=[[time_array objectAtIndex:1] intValue];
                                    
                                }
                                else{
                                    hour=0;
                                    minute=0;
                                }
                                
                            }
                            else if([[tradetime lowercaseString] hasSuffix:@"pm"] ){
                                 
                                tradetime=[tradetime stringByReplacingOccurrencesOfString:@"pm" withString:@""] ;                            
                                NSArray *time_array;
                                time_array=[tradetime componentsSeparatedByString:@":"];
                                if ([time_array count]==2) {
                                    hour=[[time_array objectAtIndex:0] intValue]+12;
                                    minute=[[time_array objectAtIndex:1] intValue];
                                    
                                }
                                else{
                                    hour=0;
                                    minute=0;
                                }
                                
                                
                                
                            }
                            else{
                                NSLog(@"no");
                                hour=0;
                                minute=0;
                                
                            }
                            
                        }
                        
                        //將取出的時間日期資料轉換成NSDate
                        {
                            NSCalendar *gregorian=[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
                            //假設yahoo 的資料員都是設定從紐約來的
                            [gregorian setTimeZone:[NSTimeZone timeZoneWithName:@"America/New_York"]];
                            
                            //[NSTimeZone timeZoneForSecondsFromGMT:8];
                            
                            NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
                            [timeZoneComps setYear:year];
                            [timeZoneComps setMonth:month];
                            [timeZoneComps setDay:day];
                            [timeZoneComps setHour:hour];
                            [timeZoneComps setMinute:minute];
                            
                            NSDate *date111=[gregorian dateFromComponents:timeZoneComps];                          
                            [gregorian release];
                            [timeZoneComps release];
                            //將時間日期再度轉換
                            // NSTimeZone *TimeZone = [NSTimeZone timeZoneWithAbbreviation:@"HKT"];                            
                           
                            NSLog(@"Symbol_converTo_timeZoneWithName=%@", [self Symbol_converTo_timeZoneWithName:code]);
                            
                            NSTimeZone *TimeZone =[NSTimeZone timeZoneWithName: [self Symbol_converTo_timeZoneWithName:code]];                            
                           
                            {//標記: 檢查Yahoo報價日期是否超過目前時間 不合理
                                
                                //下面這段程式是用來調整報價日期超過現在的時間
                                NSDate *nowddate;
                                nowddate=[NSDate date];
                                NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
                                dateFormatter.dateFormat = @"MMdd";
                                [dateFormatter setTimeZone:TimeZone];                              
                                
                                NSString *nows_time=[dateFormatter stringFromDate:nowddate];
                                NSString *quote_time=[dateFormatter stringFromDate:date111];
                                
                                NSLog(@"now_time=%@",nows_time);
                                NSLog(@"quote_time=%@",quote_time);
                                
                                if ([quote_time intValue]-[nows_time intValue] >=1) {
                                    NSTimeInterval seconds = fabs(60.0 * 60.0 * 24.0 * 1.0 * 1);                                    
                                    date111=[date111  dateByAddingTimeInterval: -1 * seconds];                               
                                    
                                }
                                [dateFormatter release];
                                //下面這段程式是用來調整如果日期是星期六 或是星期日
                                
                                NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
                                [gregorian setTimeZone:TimeZone];                                
                                
                                
                                NSDateComponents *weekdayComponents =
                                [gregorian components:NSWeekdayCalendarUnit fromDate:date111];
                                
                                NSInteger weekday = [weekdayComponents weekday];
                                NSLog(@"WEEKDAY=%i",weekday);
                                
                                //下面的調整方法只是將錯誤的日期往前推到星期五
                                if (weekday==7) {
                                    //如果是星期六
                                    NSTimeInterval seconds = fabs(60.0 * 60.0 * 24.0 * 1.0 * 1);                                    
                                    date111=[date111  dateByAddingTimeInterval: -1 * seconds];                                     
                                    
                                }
                                if (weekday==1) {
                                    //如果是星期日                                    
                                    NSTimeInterval seconds = fabs(60.0 * 60.0 * 24.0 * 1.0 * 1);                                    
                                    date111=[date111  dateByAddingTimeInterval: -2 * seconds];                                     
                                    
                                }                                
                                
                                
                                [gregorian release];                                
                                
                            } 
                            
                            NSDateFormatter *dateFormatter_MMdd = [[NSDateFormatter alloc] init];
                            dateFormatter_MMdd.dateFormat = @"MM/dd/yyyy";
                            [dateFormatter_MMdd setTimeZone:TimeZone];                            
                            
                            NSDateFormatter *dateFormatter_HHmm = [[NSDateFormatter alloc] init];
                            dateFormatter_HHmm.dateFormat = @"K:mm aa";
                            [dateFormatter_HHmm setTimeZone:TimeZone];
                            
                            
                            NSString *timeStamp_HHmm = [dateFormatter_HHmm stringFromDate:date111];
                            NSString *timeStamp_MMdd = [dateFormatter_MMdd stringFromDate:date111];                            
                            
                            tradedate=timeStamp_MMdd;
                            tradetime=timeStamp_HHmm;
                            
                            [dateFormatter_MMdd release];
                            [dateFormatter_HHmm release];                           
                            
                            
                        }
                        
                        
                        
                        
                        updown=[pdata objectAtIndex:4] ;
                        updown=[[NSString alloc] initWithString:updown];
                        
                        updownPercent=[[pdata objectAtIndex:5] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ];
                        updownPercent=[[NSString alloc] initWithString:updownPercent];
                        volume_yahoo=[[pdata objectAtIndex:9] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ] ;
                        EPS_Estimate_Current_Year_yahoo=[[pdata objectAtIndex:10] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ] ;
                        Price_EPS_Estimate_Next_Year_yahoo =[[pdata objectAtIndex:11] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ] ;
                        //  NSLog(@"a1open retain=%i",[open retainCount]);
                        
                        open=[[pdata objectAtIndex:12] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ]   ;
                        
                        
                        NSLog(@"a2open retain=%i",[open retainCount]);                                     
                        
                        high=[[pdata objectAtIndex:13] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ]  ;
                        
                        low=[[pdata objectAtIndex:14] stringByReplacingOccurrencesOfString:@"\"" withString:@"" ]   ;
                        
                        
                        activity=[NSNumber numberWithBool:NO ];
                        his=[pdata objectAtIndex:1] ;						
						
						if ([updownPercent hasPrefix:@"+" ]  ) {
							//NSString *y;
							//y=[updownPercent stringByReplacingOccurrencesOfString:@"+" withString:@""];
							//y=[y stringByReplacingOccurrencesOfString:@"%" withString:@""];
							num_updownpercent= [NSNumber numberWithFloat:[updownPercent floatValue]];
						}						
						else  if ([updownPercent hasPrefix:@"-" ]  ) {
							//NSString *y;
							//y=[updownPercent stringByReplacingOccurrencesOfString:@"-" withString:@""];
							//y=[y stringByReplacingOccurrencesOfString:@"%" withString:@""];
							num_updownpercent= [NSNumber numberWithFloat:[updownPercent floatValue]];
						}	
						else   {
							//NSString *y;
							//y=@"0"; 
							num_updownpercent= [NSNumber numberWithFloat:[updownPercent floatValue]];
						}	
						
						
                        
                        
						DataObject *temp = [  [DataObject alloc] init]  ;						
                        // NSLog(@"1temp retain=%i",[temp retainCount]);                         
						int indexofcode;
						indexofcode=[data_code indexOfObject:[[pdata objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""]];
                        
                        if(indexofcode==2147483647){
                            
                            [temp Copy_symbol:code];                            
                            temp.name=[ pdata objectAtIndex:0];									
                            //name =[ pdata objectAtIndex:0 ];
						    id_class=[pdata objectAtIndex:0 ];								
							
						}
						else {
							
                            //name=[data_name objectAtIndex:indexofcode ];	//錯誤
                            
                            
							if (indexofcode>=[data_id_class count] ) {
                                
                                id_class =@"Na" ;
							}
							else {
                                
                                id_class=[data_id_class objectAtIndex:indexofcode ];
								
							}
                            
                            [temp Copy_symbol:code];
                            temp.name=[data_name objectAtIndex:indexofcode ];							 						
							
						}
						
                        [temp isUsexxTradexxForBackUpData];
                        
						temp.lastprice=lastprice;
                        
                        
                        [temp Copy_open: open];
						[temp Copy_high: high];
						[temp Copy_low:low];
                        
                        [temp Copy_tradedate: tradedate];
                        [temp Copy_tradetime:tradetime];
                        
						[temp Copy_updown: updown];
                        [temp Copy_updownPercent:updownPercent];
                        
						temp.activity=activity;
						temp.his=his;
						temp.id_class=id_class;
						temp.volume_yahoo=volume_yahoo;
						temp.EPS_Estimate_Current_Year_yahoo=EPS_Estimate_Current_Year_yahoo;
						temp.Price_EPS_Estimate_Next_Year_yahoo=Price_EPS_Estimate_Next_Year_yahoo;
						
						temp.Nupdwonpercent=num_updownpercent;
						temp.Nupdwon=[NSNumber numberWithFloat:[updown floatValue]];
                        
                        //此段程式是用來檢查收盤價是否不合理價位過高 因為yahoo在回補資料時有時會出現錯誤
						//所以需要重新回補
						
						if ([lastprice floatValue]>999999) {
							 
							[temp_data_code addObject: code  ];
						}
						else {
                            
                            
							[download_data_obj addObject:  temp   ];
                            
                            
                        }
                        NSLog(@"f");
                        [temp release];
                        NSLog(@"g");
                        
                        
					}						
                    
                    
				}
				
			}
		}
        }
        else{
        //google
            NSString *code;
            NSString *lastprice;
            NSString *open;
            NSString *high;
            NSString *low;
            
            NSString *tradedate;
            NSString *tradetime;
            NSString *updown;
            NSString *updownPercent;
            NSNumber *activity;
            NSString *his;
            NSString *volume_yahoo;
            NSString *EPS_Estimate_Current_Year_yahoo;
            NSString *Price_EPS_Estimate_Next_Year_yahoo;						
             						
            NSString *id_class;
            NSNumber *num_updownpercent;  
            
             
                      
            activity=[NSNumber numberWithBool:NO ];
            
            
            his=@"999";
            Price_EPS_Estimate_Next_Year_yahoo=@"999";						
            //name=@"999";
            //id_class=@"999";
            num_updownpercent=[NSNumber numberWithBool:NO ];  
           // download_string=@"999";
            
            
            
            
            //去除無用的字串 '//' 還有 "\" 
            
            NSString *string_for_jsonvalue=  [[datas stringByReplacingOccurrencesOfString: @"//" withString:@"" ]stringByReplacingOccurrencesOfString: @"\\" withString:@""  ]  ;
            
            NSLog(@"%@",string_for_jsonvalue);
            
            //將字串的每個elements 分解出來      
            NSArray *jsonvalue_elements = [string_for_jsonvalue JSONValue];
            
            for (NSDictionary *s in jsonvalue_elements ) {
                NSLog(@"s=%@",s);
                //取出每個objects 的值
               
                NSLog(@"yahoo symbol= %@" , [self TickerConvert_google_yahoo: [s objectForKey:@"t"] ] );            
                NSLog(@"l=%@",[s objectForKey:@"l"]  );   //收盤價
                NSLog(@"lt=%@",[s objectForKey:@"lt"]  );            
                NSLog(@"ltt=%@",[s objectForKey:@"ltt"]  );  
                NSLog(@"c=%@",[s objectForKey:@"c"]  );//漲跌          
                NSLog(@"c=%@",[s objectForKey:@"cp"]  );  //漲跌福
                NSLog(@"op=%@",[s objectForKey:@"op"]  );  //oplen        
                NSLog(@"hi=%@",[s objectForKey:@"hi"]  );  //high  
                NSLog(@"lo=%@",[s objectForKey:@"lo"]  );  //lo
                NSLog(@"vo=%@", [s objectForKey:@"vo"]   );  //volume M百萬 B十億
                NSLog(@"eps=%@",[s objectForKey:@"eps"]  );  //volume         
                 
               
                code=[self TickerConvert_google_yahoo: [s objectForKey:@"t"] ];
                //name=[self TickerConvert_google_yahoo: [s objectForKey:@"name"] ];
             
                lastprice=[s objectForKey:@"l"];  
                open=[s objectForKey:@"op"];                 
                high=[s objectForKey:@"hi"]; 
                low=[s objectForKey:@"lo"] ;  
               
                /*
                if ([[s objectForKey:@"op"] isEqualToString:@""]) {
                  open=[s objectForKey:@"l"];
                }
                else{
                  open=[s objectForKey:@"op"]; 
                }
               
                if ([[s objectForKey:@"hi"] isEqualToString:@""]) {
                   high=[s objectForKey:@"l"];
                }
                else{
                   high=[s objectForKey:@"hi"];
                }
                
                if ([[s objectForKey:@"lo"] isEqualToString:@""]) {
                   low=[s objectForKey:@"l"];
                }
                else{
                   low=[s objectForKey:@"lo"] ;     
                }                
                */
                              
               
                          
                //tradetime
                {
                    NSArray * ltt_array=[[s objectForKey:@"ltt"] componentsSeparatedByString:@" "];                 
                    if ([ltt_array count]==2) {
                        tradetime=[ltt_array objectAtIndex:0]; 
                    }
                    else{
                        tradetime=@"N/A";
                    }
                
                }
                //tradedate             
                {
                    NSArray * lt_array=[[s objectForKey:@"lt"] componentsSeparatedByString:@","];                 
                    if ([lt_array count]==2) {
                        //因為google 無年資料 所以就以系統年資料為主
                        NSLog(@"tradedate a=%@",[lt_array objectAtIndex:0]);
                        
                        NSDate *date=[NSDate date];
                        NSDateFormatter *dateFormatter_yyyy = [[NSDateFormatter alloc]init];                        
                        [dateFormatter_yyyy setDateFormat:@"yyyy"];
                        NSString *year_google=[dateFormatter_yyyy stringFromDate:date];
                        int month,day;
                        month=1;
                        day=1;
                        NSArray * date_array=[[lt_array objectAtIndex:0] componentsSeparatedByString:@" "]; 
                       
                        if ([date_array count]==2) {
                            month=[self MMM_MonthConvertToInterger:[date_array objectAtIndex:0]];
                            day=[[date_array objectAtIndex:1] intValue];
                        }
                        
                        //檢查日期是否符合標準
                        if ((day>0 && day<32) &&( month>0 && month<13)  ) {
                            
                            tradedate=[NSString stringWithFormat:@"%i/%i/%@",month,day,year_google];                        
                            
                        }
                        else{
                            
                            tradedate=@"N/A";                        
                        }
                        
                       
                        [dateFormatter_yyyy release];
                    
                    }
                    else{
                         tradedate=@"N/A";
                    }
                    
                }                
                
                updown=[s objectForKey:@"c"];
                updownPercent=[NSString stringWithFormat:@"%@%%",[s objectForKey:@"cp"]];                
                
                //Volume
                {
                    if ([[s objectForKey:@"vo"] hasSuffix:@"M"]  ) {
                        volume_yahoo=[s objectForKey:@"vo"] ;                       
                    }
                    else{
                        NSArray * vo_array=[[s objectForKey:@"vo"] componentsSeparatedByString:@"."];                 
                        
                        if ([vo_array count]==2) {
                            volume_yahoo=[vo_array objectAtIndex:0]; 
                        }
                        else{
                            volume_yahoo=[s objectForKey:@"vo"] ;
                        } 
                        
                        
                    }
                    
                    
                    
                }
                 EPS_Estimate_Current_Year_yahoo=[s objectForKey:@"eps"];                   
                
                    
                
                DataObject *temp = [  [DataObject alloc] init]  ;						
                                        
                int indexofcode;
                indexofcode=[data_code indexOfObject: code ];
                
                
                if(indexofcode!=2147483647){
                    
                    
                    //name=[data_name objectAtIndex:indexofcode ];	//錯誤
                    
                    
                    if (indexofcode>=[data_id_class count] ) {
                        
                        id_class =@"Na" ;
                    }
                    else {
                        
                        id_class=[data_id_class objectAtIndex:indexofcode ];
                        
                    }
                    
                    [temp Copy_symbol:code];
                    temp.name=[data_name objectAtIndex:indexofcode ];							 						
                    [temp isUsexxTradexxForBackUpData];
                    
                    temp.lastprice=lastprice;
                    
                     
                    [temp Copy_open: open];
                    [temp Copy_high: high];
                    [temp Copy_low:low];
                    
                    [temp Copy_tradedate: tradedate];
                    [temp Copy_tradetime:tradetime];
                    
                    [temp Copy_updown: updown];
                    [temp Copy_updownPercent:updownPercent];
                    
                    temp.activity=activity;
                    temp.his=his;
                    temp.id_class=id_class;
                    temp.volume_yahoo=volume_yahoo;
                    temp.EPS_Estimate_Current_Year_yahoo=EPS_Estimate_Current_Year_yahoo;
                    temp.Price_EPS_Estimate_Next_Year_yahoo=Price_EPS_Estimate_Next_Year_yahoo;
                    
                    temp.Nupdwonpercent=num_updownpercent;
                    temp.Nupdwon=[NSNumber numberWithFloat:[updown floatValue]];
                    
                    //此段程式是用來檢查收盤價是否不合理價位過高 因為yahoo在回補資料時有時會出現錯誤
                    //所以需要重新回補
                    
                    if ([lastprice floatValue]>999999) {
                        //NSLog(@"**********************faile=%@",code);
                        [temp_data_code addObject: code  ];
                    }
                    else {
                        
                        
                        [download_data_obj addObject:  temp   ];
                        
                        
                    }
                
                
                
                
                }
                
                
                
                [temp release];
                
                                    
                
            }                       
            
            
        }
        
   	   
        
        
        
		//資料還須要繼續下載
		 
        if ([OutIdentifier isEqualToString:@"refeshQuoteObject_repeat"] || [OutIdentifier isEqualToString:@"refeshQuoteObject_start"]) {
            
			[self refeshTableQuote];
			 
		}
         
		
		//資料下載結束 還要檢查欄位是不是需要計算
		if ([OutIdentifier isEqualToString:@"refeshQuoteObject_end"]) {
			isfirstQuote=YES;	
			isDownloadQuoteNow=NO;	//報價下載資料結束		
			
            //標記:表格內展開出現日內走勢圖 日線內的暫存資料清除 (refresh)
            [self Clean_memory_intraday_data];
            
            
            
            
            
            
            
			
			[[self tableView] reloadData];		 
		    //[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
           
            //[ActivityIndicator stopAnimating];
                        
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
                [graph stopActivityIndicator];	
            }                  
                       
			// 檢查目前報價表格欄位計算是否要啓動
			//取出所有要下載的表頭欄位
			
			
			NSMutableArray *all_table_Indicator;
			all_table_Indicator=[[NSMutableArray alloc] init];
			{
				NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];			
				//0
				NSArray *csvLinesR0 = [[picka1 objectAtIndex:[[prefs objectForKey: @"tableR0" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
				for (int i=0; i<[csvLinesR0 count]; i++) {
					[all_table_Indicator addObject: [csvLinesR0 objectAtIndex:i]];
				}
				//1
				NSArray *csvLinesR1 = [[picka2 objectAtIndex:[[prefs objectForKey: @"tableR1" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
				for (int i=0; i<[csvLinesR1 count]; i++) {
					[all_table_Indicator addObject: [csvLinesR1 objectAtIndex:i]];
				}			
				//2
				NSArray *csvLinesR2 = [[picka3 objectAtIndex:[[prefs objectForKey: @"tableR2" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
				for (int i=0; i<[csvLinesR2 count]; i++) {
					[all_table_Indicator addObject: [csvLinesR2 objectAtIndex:i]];
				}				
				
			}
			
			
			isCalcuateTableIndic=NO;
			
			 
			[haveToTableCaluateIndicator release];
			haveToTableCaluateIndicator=nil;
			haveToTableCaluateIndicator=[[NSMutableArray alloc] init];
			 

			
			//從裡面搜尋
			for (int i=0; i<[all_table_Indicator count]; i++) {
				 
				
				if ([needCalcuateTableIndicator indexOfObject:[all_table_Indicator objectAtIndex:i] ]==NSNotFound ) {
					
				}
				else {
					//表示要進行計算
					[haveToTableCaluateIndicator addObject: [all_table_Indicator objectAtIndex:i]];
					 isCalcuateTableIndic=YES;			
				}
				
				
			}
			[all_table_Indicator release];
			
			//如果欄位有需要計算的 執行計算
			if (isCalcuateTableIndic==YES) {
				 //排序歸0
				 
				 sort_1_index=1;
				 
				 sort_2_index=1;	
				 
				 sort_3_index=1;	
                
                
				 [self calcuate_Table_Indicator];				
				
			}
				
            //標記:tabBarController 暫停使用 (僅在iPhone開啓使用)   
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
                
            }
            else{
                [(AppDelegate * )AppleDeglate Set_tabBarController_Enable];  
                //開始下載股價歷史資料時 將回歸扭隱藏
                NSLog(@"2=self.navigationItem.hidesBackButton=NO");
                self.navigationItem.hidesBackButton=NO;                 
            }
            
            acv.hidden=YES;            
            isRuningRefreshQuoteTable=NO;            
			
		}
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {    
            //第一次啓動繪圖 分配記憶體 
            if([(AppDelegate * )AppleDeglate agraph] ==nil)
            {
                NSLog(@"******第一次啓動繪圖 分配記憶體********");
                          
                StockGrapth *aGraph = [[StockGrapth alloc] init];
                //[self.graph release];
                 self.graph = aGraph;
                [(AppDelegate * )AppleDeglate setAgraph:aGraph];
                aGraph.AppleDeglate=AppleDeglate;
                aGraph.delgete=self;
                aGraph.graph_dwm=Gdwm;
                [aGraph release];
            }
            else{
                NSLog(@"******使用舊的走勢圖記憶體********");     
                self.graph =    [(AppDelegate * )AppleDeglate agraph]; 
                self.graph.delgete=self;         
            }
            
            
            
            //取的歷史資料過程
            
            if (downhistoryindex<0) {
                
               // DataObject *dobe;
                if ([download_data_obj count]<GraphIndex) {
                       GraphIndex=0;//將位置重設
                }
               
                //前一各繪圖位置
               // previous_index=  GraphIndex;              
                
               // dobe=[download_data_obj objectAtIndex:GraphIndex];
               // [dobe dealloc_financialData];	
                
                //標記: 清除最小股票單位資料物件
                GraphIndex=0;//將位置重設
                
                
                
                DataObject *dob;
                dob=[download_data_obj objectAtIndex:0];	
                dob.delgete=self;	
                dob.dwm=Gdwm;
                BOOL isUsedFileData;
                isUsedFileData=[dob getYahooHistroryDatagraphindex:0 
                                                       writetofile:YES 
                                                         drawChart:YES
                                        closeCellActivityIndicator:NO
                                                  isuseNavagarator:YES
                                              isresetGraphLocation:YES 
                                                        isOptimize:NO 
                                           isCaluateTableIndicator:isCalcuateTableIndic];
                if (isUsedFileData) {
                    
                    downhistoryindex=-1;
                    //表示 是由檔案先取出資料 
                    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
                   // [ActivityIndicator startAnimating];	
                     acv.hidden=NO;                    
                }
                else {
                    
                    // 表示無檔案資料 歷史資料是從網路下載
                    downhistoryindex=-1;	
                    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
                    //[ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
                     acv.hidden=NO;
                }
                
                
                
                
            }
            
            //!
            
            
            
        }	
	}
	
	//NSLog(@" datas retainCount  =%i",[datas retainCount]   );
    
     
   
	    
    
	NSLog(@"Download_Finish:_end");
}


//下載資料失敗

-(void)Download_didFailWithError:(NSError *)error Oidentifier:(NSString*)OutIdentifier{
	UIAlertView *av;
	//av=[[UIAlertView alloc] initWithTitle:@"網路錯誤" message: [[error userInfo] description]   delegate:self cancelButtonTitle:@"ggg" otherButtonTitles:@"gg",nil];
	av=[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No Internet Connection",@"No Internet Connection") message:NSLocalizedString(@"Tap 'Retry' to Reload Data ",@"Tap 'Retry' to Reload Data ") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",@"Cancel") otherButtonTitles:NSLocalizedString(@"Retry",@"Retry"),nil];
 	
	
	[av show];
    [av release];
	//[ActivityIndicator stopAnimating];
	 acv.hidden=YES;    
    isRuningRefreshQuoteTable=NO;
     
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        [graph stopActivityIndicator];	
    }          
    
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
	 
	
	//表示網路警示視窗 被人按下 retry
	if (buttonIndex==1) {
		NSLog(@"之前網路斷線 現在重新開啓");
		[self refeshTableQuote];
	}
	
}

#pragma mark -
#pragma mark Graph  表格觸控 delegate 方法 啓動走勢圖關鍵方法
-(void)SegmetnctlChange:(NSString *)Cdwm indexr:(NSUInteger)indexrow{
	NSLog(@"SegmetnctlChange_start");	
    //標記:tabBarController 暫停使用 (暫停使用  SegmetnctlChange)   
    [(AppDelegate * )AppleDeglate Set_tabBarController_DisEnable];
	 
    //開始下載股價歷史資料時 將回歸扭隱藏
    graph.navigationItem.hidesBackButton=YES;	
    
    
	Gdwm=Cdwm;
	
	//將位置重設
	if (GraphIndex==[download_data_obj count]) {
		GraphIndex=0;
	}
	
		DataObject *dob;
		dob=[download_data_obj objectAtIndex:GraphIndex];	
		dob.dwm=Gdwm;
		dob.delgete=self;	
		 
        [dob getYahooHistroryDatagraphindex:GraphIndex 
												writetofile:YES 
												  drawChart:YES
								 closeCellActivityIndicator:NO
										   isuseNavagarator:NO
									   isresetGraphLocation:YES 
												 isOptimize:NO 
									isCaluateTableIndicator:NO];
		
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                 
    //標記:Yahoo與Google 資料選擇修改位置 歷史資料下載分野        
    if ([[prefs objectForKey:@"isYahoo"] boolValue]==YES)  {                 
        
        downhistoryindex=-1;	
        [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
        //[ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
         acv.hidden=NO;        
    }   

 
	
	NSLog(@"SegmetnctlChange_end");	
}
-(void)PreviousDrawGraph:(NSUInteger)indexrow{
    
    //DataObject *dobe;
    //dobe=[download_data_obj objectAtIndex:GraphIndex];
    //[dobe dealloc_financialData];	
    
    //前一各繪圖位置
    //previous_index=  GraphIndex;  	
    //標記: 清除最小股票單位資料物件
    NSLog(@"PreviousDrawGraph1");
    GraphIndex=GraphIndex+1;//將位置重設
	if (GraphIndex==[download_data_obj count]) {
		GraphIndex=0;
	}
	 NSLog(@"PreviousDrawGraph2");
	DataObject *dob;
	dob=[download_data_obj objectAtIndex:GraphIndex];	
	dob.dwm=Gdwm;
	dob.delgete=self;	
	
	BOOL isUsedFileData;
	isUsedFileData= [dob getYahooHistroryDatagraphindex:GraphIndex 
											writetofile:YES 
											  drawChart:YES
							 closeCellActivityIndicator:NO
									   isuseNavagarator:NO 
								   isresetGraphLocation:YES 
											 isOptimize:NO 
								isCaluateTableIndicator:NO];
	
	
	if (isUsedFileData) {
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
		//[ActivityIndicator startAnimating];			
		 acv.hidden=NO;
	}
	else {
		
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
		//[ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
		 acv.hidden=NO;
	}		
	
	
	
}
-(void)NextDrawGraph:(NSUInteger)indexrow{
   // DataObject *dobe;
    //dobe=[download_data_obj objectAtIndex:GraphIndex];
   // [dobe dealloc_financialData];	
    //前一各繪圖位置
   // previous_index=  GraphIndex;  		
    //標記: 清除最小股票單位資料物件
	
    GraphIndex=GraphIndex-1;//將位置重設
	NSLog(@"NextDrawGraph1");
	if (GraphIndex==-1) {
		GraphIndex=[download_data_obj count]-1;
	}
	NSLog(@"NextDrawGraph2");    
	DataObject *dob;
	dob=[download_data_obj objectAtIndex:GraphIndex];	
	dob.delgete=self;
	dob.dwm=Gdwm;
	
	BOOL isUsedFileData;
	isUsedFileData=	[dob getYahooHistroryDatagraphindex:GraphIndex 
											writetofile:YES 
											  drawChart:YES
							 closeCellActivityIndicator:NO
									   isuseNavagarator:NO 
								   isresetGraphLocation:YES  
											 isOptimize:NO 
								isCaluateTableIndicator:NO];	
	
	
	if (isUsedFileData) {
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
		//[ActivityIndicator startAnimating];			
		 acv.hidden=NO;
	}
	else {
		
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
		//[ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
		 acv.hidden=NO;
	}			
}
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     
    // StockTableQuoteCell *cell=(StockTableQuoteCell *)[tableView cellForRowAtIndexPath:indexPath];
     
      
     
     
     
     //標記:判斷是MESA或LF
     NSString *DisplayName;
     DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
     NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
     
     if ([DisplayName_array count]>=3) {
         if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
             //開始MESA
                       
             //標記:表格內展開出現日內走勢圖 點擊後來判斷是否要擴展或是縮減
             if ( [expand_table_code indexOfObject:[NSString stringWithFormat:@"%i",indexPath.row]]!=NSNotFound) {
                [expand_table_code  removeObject: [NSString stringWithFormat:@"%i",indexPath.row]];
                                 
                [tableView reloadData]; 
             }
             else{
                
                 
                 [expand_table_code addObject:[NSString stringWithFormat:@"%i",indexPath.row]];
                
                      
                 
                 [tableView reloadData]; 
             }
              
         
         
         }
         else{
             //開始LF
             NSLog(@"tableView didSelectRowAtIndexPath_start");
             //標記:tabBarController 暫停使用 (暫停使用  tableView didSelectRowAtIndexPath)   
             
             [(AppDelegate * )AppleDeglate Set_tabBarController_DisEnable];
             
             
             //開始下載股價歷史資料時 將回歸扭隱藏
             self.navigationItem.hidesBackButton=YES; 
             
             if (downhistoryindex<0) {
                 acv.hidden=NO;                 
                 
                 //[ActivityIndicator startAnimating];	
                 //navdelegete.navigationItem.hidesBackButton=YES;
                 //停止轉動
                 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
                 UIView *accessory = [cell accessoryView];
                 if ([accessory isMemberOfClass:[UIActivityIndicatorView class]]) {
                     [(UIActivityIndicatorView *) accessory stopAnimating];
                     [cell setAccessoryView:nil];
                 }	
                 
                 if(![(AppDelegate * )AppleDeglate agraph] )
                 {
                     NSLog(@"******第一次啓動繪圖 分配記憶體********");
                     
                     StockGrapth *aGraph = [[StockGrapth alloc] init];
                     
                     self.graph = aGraph;
                     [(AppDelegate * )AppleDeglate setAgraph:aGraph];
                     aGraph.AppleDeglate=AppleDeglate;
                     aGraph.delgete=self;
                     aGraph.graph_dwm=Gdwm;
                     [aGraph release];
                 }
                 else{
                     NSLog(@"******使用舊的走勢圖記憶體********");     
                     self.graph =    [(AppDelegate * )AppleDeglate agraph]; 
                     self.graph.delgete=self;         
                 }
                 
                
                 
                 
                 
                 
                 
                 //取的歷史資料過程
                 
                 //DataObject *dobe;
                 //dobe=[download_data_obj objectAtIndex:GraphIndex];
                 //[dobe dealloc_financialData];	
                 //前一各繪圖位置
                 // previous_index=  GraphIndex;          
                 //標記: 清除最小股票單位資料物件
                
                 GraphIndex=indexPath.row;//將位置重設
                 
                 DataObject *dob;
                 dob=[download_data_obj objectAtIndex:indexPath.row];	
                 dob.delgete=self;	
                 dob.dwm=Gdwm;
                  
                
                 [dob getYahooHistroryDatagraphindex:indexPath.row 
                                                        writetofile:YES 
                                                          drawChart:YES
                                         closeCellActivityIndicator:NO
                                                   isuseNavagarator:YES
                                               isresetGraphLocation:YES 
                                                         isOptimize:NO 
                                            isCaluateTableIndicator:NO];
                
                 NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                 
                 //標記:Yahoo與Google 資料選擇修改位置 歷史資料下載分野        
                 if ([[prefs objectForKey:@"isYahoo"] boolValue]==YES)  {                 
                     
                     downhistoryindex=-1;	
                     [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
                     //[ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
                     acv.hidden=NO;                 
                 }   
                 
                                  
                 
                 
                 
                 
             }
             
             NSLog(@"tableView didSelectRowAtIndexPath_end a");             
             
             
             
                        
         }
     }
     else{
                
     }
     
     
     
     
     
     
     
  
     /*
     
    
     */
     
     
}


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];    
    
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //開始MESA
            //開始LF
            NSLog(@"tableView didSelectRowAtIndexPath_start");
            //標記:tabBarController 暫停使用 (暫停使用  tableView didSelectRowAtIndexPath)   
            
            [(AppDelegate * )AppleDeglate Set_tabBarController_DisEnable];
            
            
            //開始下載股價歷史資料時 將回歸扭隱藏
            self.navigationItem.hidesBackButton=YES; 
            if (downhistoryindex<0) {     
                acv.hidden=NO;
                //[ActivityIndicator startAnimating];	
                //navdelegete.navigationItem.hidesBackButton=YES;
                //停止轉動
                UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
                UIView *accessory = [cell accessoryView];
                if ([accessory isMemberOfClass:[UIActivityIndicatorView class]]) {
                    [(UIActivityIndicatorView *) accessory stopAnimating];
                    [cell setAccessoryView:nil];
                }	
                
                if([(AppDelegate * )AppleDeglate agraph] ==nil)
                {
                    NSLog(@"******第一次啓動繪圖 分配記憶體********");
                    
                    StockGrapth *aGraph = [[StockGrapth alloc] init];
                     
                    self.graph = aGraph;
                    [(AppDelegate * )AppleDeglate setAgraph:aGraph];
                    aGraph.AppleDeglate=AppleDeglate;
                    aGraph.delgete=self;
                    aGraph.graph_dwm=Gdwm;
                    [aGraph release];
                }
                else{
                    NSLog(@"******使用舊的走勢圖記憶體********");     
                    self.graph =    [(AppDelegate * )AppleDeglate agraph]; 
                    self.graph.delgete=self;         
                }
                
                
                
                
                //======================
                
             
                
                
                
                
                
                
                //取的歷史資料過程
                
                
                
                //DataObject *dobe;
                //dobe=[download_data_obj objectAtIndex:GraphIndex];
                //[dobe dealloc_financialData];	
                //前一各繪圖位置
                // previous_index=  GraphIndex;          
                //標記: 清除最小股票單位資料物件
                GraphIndex=indexPath.row;//將位置重設
                
                
                
                DataObject *dob;
                dob=[download_data_obj objectAtIndex:indexPath.row];	
                dob.delgete=self;	
                dob.dwm=Gdwm;
                 
                [dob getYahooHistroryDatagraphindex:indexPath.row 
                                                       writetofile:YES 
                                                         drawChart:YES
                                        closeCellActivityIndicator:NO
                                                  isuseNavagarator:YES
                                              isresetGraphLocation:YES 
                                                        isOptimize:NO 
                                           isCaluateTableIndicator:NO];
              
                NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                
                //標記:Yahoo與Google 資料選擇修改位置 歷史資料下載分野        
                if ([[prefs objectForKey:@"isYahoo"] boolValue]==YES)  {                 
                    
                    downhistoryindex=-1;	
                    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	//==============
                   // [ActivityIndicator startAnimating];		//NSLog(@"a322 downhistoryindex=%i",downhistoryindex);
                    acv.hidden=NO;            
                }  	                    
                
                //[self DelgetestopAnimating];               
                
            }
           
           
            
            
            
            NSLog(@"tableView didSelectRowAtIndexPath_end b");             
           // [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
           // [ActivityIndicator stopAnimating];	                       
                 
            
            
        }
        else{
            
        }
    }
    else{
        
    }
    
     

}



#pragma mark -
#pragma mark  TableBarController 是否可以點選
 

/*
 如果修改 tableView didSelectRowAtIndexPath
 則
 1. -(void)SegmetnctlChange:(NSString *)Cdwm indexr:(NSUInteger)indexrow
 2. -(void)PreviousDrawGraph:(NSUInteger)indexrow
 3. -(void)NextDrawGraph:(NSUInteger)indexrow 
 也要注意是否需要修改 
 
 */


#pragma mark -
#pragma mark DataObject  delegate 方法(最佳化結束)
-(void)afterOptimize{
	NSLog(@"afterOptimize");
   

	//使table cell 上出現進度指示器 關閉
	if([download_data_obj count]>0) {
		//移除第一列
		//[[download_data_obj objectAtIndex:0] release];
		[download_data_obj removeObjectAtIndex:0];
		//重刷表格資料
		[[self tableView] reloadData];		
		[self refreshALL:nil];
		 
	}   
}
#pragma mark -
#pragma mark DataObject  delegate 方法(報價指標計算結束)
-(void)afteCaluateTableIndicator{
	
	
     if (index_CaluateTableIndicator<[download_data_obj count]) {
        DataObject *ob;
        ob=[download_data_obj objectAtIndex:index_CaluateTableIndicator];
        ob.activity= [NSNumber numberWithBool:NO];
        
         NSLog(@"報價指標計算結束=%i ",index_CaluateTableIndicator);         
               
        index_CaluateTableIndicator =index_CaluateTableIndicator +1;//將進度畫面銷除	
        [self calcuate_Table_Indicator];   
     }
	
    [self.tableView reloadData]	;
}
#pragma mark -
#pragma mark DataObject  delegate 方法(用於歷史資料的回補)

//物件已經下載完資料 啓動關閉表格的進度顯示器
 
-(void)closeCellActivityIndicator:(NSUInteger)indexrow symbol:(NSString *)csymbol{
	//總進度顯示器+1
	/*
	[self incrementBara:csymbol];
	DataObject *ob;
	ob=[download_data_obj objectAtIndex:indexrow];
	ob.activity=[NSNumber numberWithBool:NO];
	[[self tableView] reloadData];	
    */

}
-(void)DelgetestopAnimating{
	  NSLog(@"DelgetestopAnimating");    
    //進入繪圖階段
	   [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
	  // [ActivityIndicator stopAnimating];	
      acv.hidden=YES;    
      isRuningRefreshQuoteTable=NO;    
      //canRuningRefreshQuoteTable=YES;
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
       // [graph stopActivityIndicator];	
        
               
        
    }  
    
    //標記: 清除最小股票單位資料物件
     NSLog(@"1清除最小股票單位資料物件");
    if (previous_index>=0 && previous_index !=GraphIndex ) {
        NSLog(@"2清除最小股票單位資料物件");
       
        if (previous_index<[download_data_obj count]) {
            DataObject *dobe;
            dobe=[download_data_obj objectAtIndex:previous_index];
            [dobe dealloc_financialData]; 
        }
              
        
        previous_index=  GraphIndex;   
    }
    else{
        previous_index=  GraphIndex;  
    }
         
       
    
    //消除前一各股票資料
       	
       
    
    
	
}

-(void)StartDrawGraph:(NSUInteger)indexrow isusdNavagarator:(BOOL)usedNavagarator isresetGraphLocation:(BOOL)isResetGraphLocationa{
	 NSLog(@"StartDrawGraph_start");
	//已經下載完資料要繪圖時 回復隱藏
	NSLog(@"1=self.navigationItem.hidesBackButton=NO");
    self.navigationItem.hidesBackButton=NO; 
	
	// NSLog([download_data_code objectAtIndex:indexrow]);
	 if (isResetGraphLocationa==YES) {
         [self.graph get_stockdata:[download_data_obj objectAtIndex:indexrow]];
         [self.graph resetLocationData];		 
		 
	 }
      //NSLog(@"aaaaa");
	 
	 if (usedNavagarator) {
		// NSLog(@"bbbb");
		 //進入繪圖階段
		  [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
		  //[ActivityIndicator stopAnimating];
          acv.hidden=YES;         
           isRuningRefreshQuoteTable=NO;
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
             [graph stopActivityIndicator];	
         }                 
         
		 [self.graph get_stockdata:[download_data_obj objectAtIndex:indexrow]];
		 
                
         
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
             // [navdelegete pushViewController:self.graph animated:YES];
         }         
         else{
             [navdelegete pushViewController:self.graph animated:YES];
         
         }
         
         
         
		 //把redrawChart 排在[navdelegete pushViewController:self.graph animated:YES];市很重要的觀念
		
		 
		 [self.graph redrawChart:isResetGraphLocationa];
		  
		 //繪圖結束後的動作
		  downhistoryindex=-1;
		 
		// [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
		// [ActivityIndicator stopAnimating];		 
		 acv.hidden=YES;		  
	 }
	 	
	 else {
	           
         
		 [self.graph get_stockdata:[download_data_obj objectAtIndex:indexrow]];
		// [navdelegete pushViewController:self.graph animated:YES];	
		 //把redrawChart 排在[navdelegete pushViewController:self.graph animated:YES];市很重要的觀念
	 	 
		 if (isResetGraphLocationa) {
			 //因為切換日週月的關係 所以必須將位置資訊重新設定
			 
			// [self.graph resetLocationData]; 
		 }
		 
		// [self.graph resetLocationData];
		 [self.graph redrawChart:isResetGraphLocationa];
		 
		 //繪圖結束後的動作
		 downhistoryindex=-1;
		 
		 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
		 isRuningRefreshQuoteTable=NO;         
        // [ActivityIndicator stopAnimating];				 
	      acv.hidden=YES;         
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
           [graph stopActivityIndicator];	
             
             
             
         }         
        
         
         
	 }
          
    //標記:繪圖結束後的最後位置 2.StockTableQuote.m-StartDrawGraph	
	 NSLog(@"StartDrawGraph_end");
	
} //啓動繪圖功能

-(void)getERRORdownload:(NSString *)symbol{
	NSLog(@"-(void)getERRORdownload:(NSString *)symbol");
	//總進度顯示器+1
	if (isCaluateTableIndicatorNow==YES) {
		//如果正在計算報價指標
		[self afteCaluateTableIndicator];		
	}
	else if(isInOptimize==YES ) {
		[self afterOptimize];
	}
    else {
		
		[self incrementBara:symbol];	
		
		[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
		//[ActivityIndicator stopAnimating];		
         acv.hidden=YES;        
        isRuningRefreshQuoteTable=NO;        
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
            [graph stopActivityIndicator];	
        }      		
		UIAlertView *av;
		av=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error Data Or No History Data",@"Error Data Or No History Data") message:symbol delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
		[av show];
		
        //顯示回到上一頁的鈕
        self.navigationItem.hidesBackButton=NO;         
		
        downhistoryindex=-1;			
		
		
	}

	
}



//物件連線下載資料失敗
-(void)ObjectDownload_didFailWithError:(NSError *)error asymbol:(NSString *)symbol{
	NSLog(@"-(void)ObjectDownload_didFailWithError:(NSError *)error asymbol:(NSString *)symbol");
	//總進度顯示器+1	
	[self incrementBara:symbol];	
	
	isRuningRefreshQuoteTable=NO;
	//[ActivityIndicator stopAnimating];	
     acv.hidden=YES;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        [graph stopActivityIndicator];	
    }          
    
    
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;		
	UIAlertView *av;
	av=[[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error Data Or No History Data",@"Error Data Or No History Data") message:symbol delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
    [av show];
    [av release];
	downhistoryindex=-1;	
	 
}
#pragma mark -
#pragma mark 記憶體管理

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    NSLog(@"didReceiveMemoryWarning");
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
	//NSLog(@"aa");
	//[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;		
}
 
- (void)dealloc {
    NSLog(@"StockTableQuote-dealloc-start");
	
	[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;		
	
   // [headerView release];
    
    //標記:表格內展開出現日內走勢圖 記憶體清除
    [expand_table_code release];    
    [intraday_data_code release];
    [intraday_data release];
	[intraday_graph_x_length release];  
    [intraday_graph_x_high release];     
    [intraday_graph_x_low release]; 
    [intraday_graph_volume_high release];       
    [intraday_graph_volume_low release];   
    [intraday_graph_lastdayClose release];        
    
    
	[downloadobject release];
	// downloadobject=nil;
	
	[download_data release];
	
    [temp_data_code release];
	[data_code release];
	//[data_name release];
    [data_class release];
	[data_id_class release];
	//[download_data release];
	 
	[download_data_obj release];	
   // download_data_obj=nil;
    
    [Gdwm release];
	//表頭欄位
	[picka1 release];
	[picka2 release];
	[picka3 release];  
    
    [needCalcuateTableIndicator release];    
    NSLog(@"StockTableQuote-dealloc-end");
    
    //標記:為何要加入nil 在物件消除後 順便把graph.delgete=nil;  
    //就是要讓graph.delgete 忘記StockTableQuote 否則會讓StockGraph 會認為StockTableQuote還存在
    graph.delgete=nil;
    //那會何不加入 [graph.delgete release] ?因為 graph.delgete=self 而本身就已經在消滅中
     
	[super dealloc];
}
 #pragma mark -
#pragma mark  UIActionSheetDelegate <NSObject>
 
// Called when a button is clicked. The view will be automatically dismissed after this call returns

// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{
   // NSLog(@"!!!!!!!!!cancel");
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"calcuate_stop");
    calcuate_stop=YES;    
    
}

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet{
}  // before animation and showing view
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet{
}  // after animation

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
} // before animation and hiding view
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
}  // after animation



#pragma mark -
#pragma mark 離開畫面的動作 
-(void) viewWillDisappear:(BOOL)animated {
   NSLog(@"viewWillDisappear");    
    /*
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
		// back button was pressed.  We know this is true because self is no longer
		// in the navigation stack.  
		
		NSLog(@"viewWillDisappear");
		//[self cancelDownload];
		[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;	
	 
		
    }
    */
    //[super viewWillDisappear:animated];
}
#pragma mark -
#pragma mark 拉下更新
//標記:Drag Refresh HeaderView滑動事件

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;{
    NSLog(@"scrollViewWillBeginDragging");

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                 
    
    if ([[prefs objectForKey:@"CanDragToRefreshQuoteTable"] boolValue]==YES)  {                 
        
        
        if (scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f) {
            
            if (isRuningRefreshQuoteTable==YES) {
                headerView.label_state.text=NSLocalizedString(@"Updating...",  @"更新中.....");
            }
            else{
                headerView.label_state.text=NSLocalizedString(@"Pull down to update...","下拉螢幕以更新....."); 
                [headerView default_image]; 
                [headerView stop_updateing];
            }        
            
            
            
            
            
        } 
        else if (scrollView.contentOffset.y < -65.0f  ) {
            NSLog(@"scrollView.contentOffset.y=%f",scrollView.contentOffset.y);
            if(isRuningRefreshQuoteTable==NO){
                
                canRuningRefreshQuoteTable=YES;
            }
            
           
            if (isRuningRefreshQuoteTable==YES) {
                headerView.label_state.text=NSLocalizedString(@"Updating...",  @"更新中.....");
            }
            else{
                headerView.label_state.text=NSLocalizedString(@"Release to update...",  "放開螢幕以更新.....");
                [headerView stop_updateing];            
            }
            
            [headerView start_rotation];
            
            
        }
        
        NSDateFormatter *refresh_quote_time_dateFormatter = [[NSDateFormatter alloc]init];
        [refresh_quote_time_dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];    
        
        headerView.label_datetime.text=[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"Last updated:","上次更新:"), [refresh_quote_time_dateFormatter stringFromDate:refresh_quote_time]] ;   
        
        [refresh_quote_time_dateFormatter release];            
        
    }   
    
    
     
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    NSLog(@"scrollViewDidEndDragging");
       
    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];                 
    
    if ([[prefs objectForKey:@"CanDragToRefreshQuoteTable"] boolValue]==YES)  {                 
        
        if (canRuningRefreshQuoteTable==YES) {
            canRuningRefreshQuoteTable=NO;
            if (isRuningRefreshQuoteTable==NO) {
                 [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;	
                  acv.hidden=NO;                
                isRuningRefreshQuoteTable=YES;
                calcuate_stop=NO;                
                [self refeshTableQuote];
                [headerView start_updateing];
            }        
        }
     
        
    }   
    
    
    

}

#pragma mark -
#pragma mark 更新全部歷史資料時 的進度顯示器 
 

//執行進度顯示器
- (void) presentSheet{
    NSLog(@"presentSheet");
	if (!self.baseSheet) {
		 
		baseSheet = [[UIActionSheet alloc] 
					 initWithTitle:NSLocalizedString(@"Please Wait...\n\n\n\n",@"請稍等...\n\n\n\n")
					 delegate:self 
					 cancelButtonTitle:NSLocalizedString(@"Continue Calcuate",@"繼續計算")   
					 destructiveButtonTitle: nil
					 otherButtonTitles: NSLocalizedString(@"Stop Calcuate",@"停止計算"),nil];
		 
		
		UIProgressView *progbar = [[UIProgressView alloc] initWithFrame:CGRectMake(70.0f, 70.0f, 180.0f, 30.0f)];
		progbar.tag = PROGRESS_BAR;
		[progbar setProgressViewStyle: UIProgressViewStyleDefault];
		[baseSheet addSubview:progbar];
		[progbar release];
		
		UILabel *lb=[[UILabel alloc] initWithFrame:CGRectMake(35.0f, 35.0f, 250.0f,30.0f)];
        lb.tag=PROGRESS_LABEL;
		lb.backgroundColor=[UIColor clearColor];
		lb.textColor=[UIColor whiteColor];
		lb.textAlignment=UITextAlignmentCenter;
		[baseSheet addSubview:lb];
		[lb release];
         
        calcuate_stop=NO;
         
	}
    
	[baseSheet showFromTabBar:self.tabBarController.tabBar];
	// [baseSheet showInView:self.view];
	 
}
-(void)calculate_stop{
    calcuate_stop=YES;
    //canRuningRefreshQuoteTable=YES;
}
//進度顯示器+1
- (void)incrementBara:(NSString *)symbol{
 
	
	UIProgressView *progbar = (UIProgressView *)[self.baseSheet viewWithTag:PROGRESS_BAR];
    [progbar setProgress: (amountDone / progresscount)];
    
	
	UILabel *lba=(UILabel *)[self.baseSheet viewWithTag:PROGRESS_LABEL];
	
    //標記:是否移除交易所碼        
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
    
    if ([[prefs objectForKey:@"isRemoveExchangeCode"] boolValue]==YES) {
        //字串分割
        NSArray *code_exchange_Array = [symbol componentsSeparatedByString:@"."];
        if ([code_exchange_Array count]==2) {
            
            lba.text=[NSString stringWithFormat:@"%@ (%0.0f/%i)", [code_exchange_Array objectAtIndex:0],amountDone,progresscount];        
        }
        else{
             lba.text=[NSString stringWithFormat:@"%@ (%0.0f/%i)", symbol,amountDone,progresscount];
            
        }
        
    }
    else {
         lba.text=[NSString stringWithFormat:@"%@ (%0.0f/%i)", symbol,amountDone,progresscount];
    }            
   
	
    
    
    lba.textAlignment=UITextAlignmentCenter;
	
}
//進度顯示器+1
- (void)incrementBara_CaluateTableIndicator:(NSString *)symbol{
	
	
	UIProgressView *progbar = (UIProgressView *)[self.baseSheet viewWithTag:PROGRESS_BAR];
    [progbar setProgress: ((float)index_CaluateTableIndicator / (float)Total_CaluateTableIndicator)];
    
	
	UILabel *lba=(UILabel *)[self.baseSheet viewWithTag:PROGRESS_LABEL];
	
    //標記:是否移除交易所碼        
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];	
    
    if ([[prefs objectForKey:@"isRemoveExchangeCode"] boolValue]==YES) {
        //字串分割
        NSArray *code_exchange_Array = [symbol componentsSeparatedByString:@"."];
        if ([code_exchange_Array count]==2) {
            
            //lba.text=[NSString stringWithFormat:@"%@ (%0.0f/%i)", [code_exchange_Array objectAtIndex:0],amountDone,progresscount];        
            lba.text=[NSString stringWithFormat:@"%@ (%i/%i)", [code_exchange_Array objectAtIndex:0],index_CaluateTableIndicator,Total_CaluateTableIndicator];        
        }
        else{
            lba.text=[NSString stringWithFormat:@"%@ (%i/%i)", symbol,index_CaluateTableIndicator,Total_CaluateTableIndicator];
            
        }
        
    }
    else {
       lba.text=[NSString stringWithFormat:@"%@ (%i/%i)", symbol,index_CaluateTableIndicator,Total_CaluateTableIndicator];
    }               
    
    
    
    
    
}
 

#pragma mark -
#pragma mark  排序報表 新增區域

-(void)sort_table{
    //標記:表格內展開出現日內走勢圖 日線內的暫存資料清除 (sort_table)
    [self Clean_memory_intraday_data];    
    
    
    
	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	NSArray *csvLinesR ;
	//判斷要排序哪個
	switch (select_col_index) {
		case 0:{
			csvLinesR= [[picka1 objectAtIndex:[[prefs objectForKey: @"tableR0"   ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			
			select_col_index_row=(int)ceilf( (float)sort_1_index/2.0);
			select_col_index_row_updwon=sort_1_index%2 ;			
			sort_1_index= sort_1_index+1;	
			if ([csvLinesR  count]*2 < sort_1_index)	{
				sort_1_index=1;
			}	
			break;
		}
		case 1:{
			csvLinesR= [[picka2 objectAtIndex:[[prefs objectForKey: @"tableR1"   ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			select_col_index_row=(int)ceilf( (float)sort_2_index/2.0);
			select_col_index_row_updwon=sort_2_index%2 ;			
			sort_2_index= sort_2_index+1;	
			if ([csvLinesR  count]*2 < sort_2_index)	{
				sort_2_index=1;
			}				
			
			break;
		}
		case 2:{
			csvLinesR= [[picka3 objectAtIndex:[[prefs objectForKey: @"tableR2"   ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			
			select_col_index_row=(int)ceilf( (float)sort_3_index/2.0);
			select_col_index_row_updwon=sort_3_index%2 ;			
			sort_3_index= sort_3_index+1;	
			if ([csvLinesR  count]*2 < sort_3_index)	{
				sort_3_index=1;
			}				
			
			break;
		}
		default:
			break;
	}
	//防錯用
	if (select_col_index_row<1) {
		select_col_index_row=1;
	}
	
	//NSLog(@"select_col_index=%i,  select_col_index_row=%i,select_col_index_row_updwon=%i  ",select_col_index,select_col_index_row, select_col_index_row_updwon    ); 
    
	NSString *columnField=nil;
	switch (select_col_index) {
		case 0:{
			NSArray *csvLines = [[picka1 objectAtIndex:[[prefs objectForKey: @"tableR0" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			columnField=[csvLines objectAtIndex:select_col_index_row-1];
			break;
		}
		case 1:{
			NSArray *csvLines = [[picka2 objectAtIndex:[[prefs objectForKey: @"tableR1" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			columnField=[csvLines objectAtIndex:select_col_index_row-1];			
			break;
		}
		case 2:{
			NSArray *csvLines = [[picka3 objectAtIndex:[[prefs objectForKey: @"tableR2" ] intValue] ]  componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
			columnField=[csvLines objectAtIndex:select_col_index_row-1];
			break;
		}
			
			
		default:
			break;
	}	
	//新增區域 
	if ([columnField isEqualToString:NSLocalizedString(@"Change%", @"漲跌福")]) {
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_updownpercent_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_updownpercent_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Change", @"漲跌")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_updown_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_updown_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Name", @"名稱")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Name_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Name_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Symbol", @"代號")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Symbol_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Symbol_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Class", @"分類")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Class_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Class_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Price", @"價格")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Price_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Price_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Time", @"時間")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Time_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Time_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Date", @"日期")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Date_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Date_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Volume", @"成交量")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_Volume_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_Volume_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}	
	else if ([columnField isEqualToString:NSLocalizedString(@"EPS Current Year", @"今年EPS")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_EPSCurrentYear_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_EPSCurrentYear_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"PE Next Year", @"次年PE")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_PENextYear_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_PENextYear_DOWN context:nil];		
		}
        download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	
	else if ([columnField isEqualToString:NSLocalizedString(@"5Day Change%", @"5日漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_5DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_5DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"10Day Change%", @"10日漲跌幅")]) {
		
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_10DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_10DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"20Day Change%", @"20日漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_20DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_20DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];		
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"60Day Change%", @"60日漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_60DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_60DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"120Day Change%", @"120日漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_120DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_120DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];		
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"240Day Change%", @"240日漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_240DayChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_240DayChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Week Change%", @"週漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_WeekChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_WeekChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Month Change%", @"月漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MonthChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MonthChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}	
	else if ([columnField isEqualToString:NSLocalizedString(@"Quarter Change%", @"季漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_QuarterChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_QuarterChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"Year Change%", @"年漲跌幅")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_YearChange_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_YearChange_DOWN context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Signal1", @"LF_訊號1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Break P1", @"LF_關鍵價位1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Signal2", @"LF_訊號2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Break P2", @"LF_關鍵價位2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Signal3", @"LF_訊號3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Signal3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Break P3", @"LF_關鍵價位3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_BreakP3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongDay1", @"LF_買入天數1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongDay2", @"LF_買入天數2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongDay3", @"LF_買入天數3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongDay3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgDay1", @"LF_賣出天數1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgDay2", @"LF_賣出天數2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgDay3", @"LF_賣出天數3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgDay3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongProfit1", @"LF_買入獲利率1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongProfit2", @"LF_買入獲利率2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_LongProfit3", @"LF_買入獲利率3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_LongProfit3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgProfit1", @"LF_賣出獲利率1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgProfit2", @"LF_賣出獲利率2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_ShortgProfit3", @"LF_賣出獲利率3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_ShortgProfit3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	
	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_FAMA1", @"MESA_FAMA1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_FAMA2", @"MESA_FAMA2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_FAMA3", @"MESA_FAMA3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_FAMA3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_MAMA1", @"MESA_MAMA1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_MAMA2", @"MESA_MAMA2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_MAMA3", @"MESA_MAMA3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_MAMA3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Signal1", @"MESA_訊號1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Signal2", @"MESA_訊號2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Signal3", @"MESA_訊號3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Signal3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Action1", @"MESA_動作1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Action2", @"MESA_動作2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_Action3", @"MESA_動作3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_Action3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Action1", @"LF_動作1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Action1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Action1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Action2", @"LF_動作2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Action2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Action2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"LF_Action3", @"LF_動作3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_LF_Action3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_LF_Action3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongDay1", @"MESA_買入天數1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongDay2", @"MESA_買入天數2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongDay3", @"MESA_買入天數3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongDay3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgDay1", @"MESA_賣出天數1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgDay2", @"MESA_賣出天數2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgDay3", @"MESA_賣出天數3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgDay3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongProfit1", @"MESA_買入獲利率1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 			
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongProfit2", @"MESA_買入獲利率2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_LongProfit3", @"MESA_買入獲利率3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_LongProfit3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgProfit1", @"MESA_賣出獲利率1")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit1_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit1_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 	
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgProfit2", @"MESA_賣出獲利率2")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit2_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit2_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	}
	else if ([columnField isEqualToString:NSLocalizedString(@"MESA_ShortgProfit3", @"MESA_賣出獲利率3")]) {
		
		NSArray *sortWinPercentage ;
		if (select_col_index_row_updwon==1) {
			sortWinPercentage= [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit3_UP  context:nil];		
		}
		else {
			sortWinPercentage=  [download_data_obj sortedArrayUsingFunction:comparator_MESA_ShortgProfit3_DOWN   context:nil];		
		}
		download_data_obj=[sortWinPercentage mutableCopy];
		[[self tableView] reloadData];	
	} 		
	
	
	
	
	
}

//漲跌福
NSInteger comparator_updownpercent_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.Nupdwonpercent compare: d1.Nupdwonpercent];
} 
NSInteger comparator_updownpercent_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.Nupdwonpercent compare: d2.Nupdwonpercent];
}
//漲跌
NSInteger comparator_updown_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.Nupdwon compare: d1.Nupdwon];
} 
NSInteger comparator_updown_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.Nupdwon compare: d2.Nupdwon];
}
//名稱
NSInteger comparator_Name_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.name compare: d1.name];
} 
NSInteger comparator_Name_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.name compare: d2.name];
}
//代號
NSInteger comparator_Symbol_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.symbol compare: d1.symbol];
} 
NSInteger comparator_Symbol_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.symbol compare: d2.symbol];
}
//分類
NSInteger comparator_Class_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.id_class compare: d1.id_class];
} 
NSInteger comparator_Class_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.id_class compare: d2.id_class];
}


//價格
NSInteger comparator_Price_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.lastprice floatValue]] compare: [NSNumber numberWithFloat: [d1.lastprice floatValue ]]];
} 
NSInteger comparator_Price_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.lastprice floatValue]] compare: [NSNumber numberWithFloat: [d2.lastprice floatValue ]]];
	
}
//時間
NSInteger comparator_Time_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.tradetime compare: d1.tradetime];
} 
NSInteger comparator_Time_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.tradetime compare: d2.tradetime];
}
//日期
NSInteger comparator_Date_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ d2.tradedate compare: d1.tradedate];
} 
NSInteger comparator_Date_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ d1.tradedate compare: d2.tradedate];
}
//成交量
NSInteger comparator_Volume_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.volume_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d1.volume_yahoo floatValue ]]];
} 

NSInteger comparator_Volume_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.volume_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d2.volume_yahoo floatValue ]]];
}
//今年EPS
NSInteger comparator_EPSCurrentYear_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.EPS_Estimate_Current_Year_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d1.EPS_Estimate_Current_Year_yahoo floatValue ]]];
} 

NSInteger comparator_EPSCurrentYear_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.EPS_Estimate_Current_Year_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d2.EPS_Estimate_Current_Year_yahoo floatValue ]]];
} 
//次年PE
NSInteger comparator_PENextYear_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.Price_EPS_Estimate_Next_Year_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d1.Price_EPS_Estimate_Next_Year_yahoo floatValue ]]];
} 
NSInteger comparator_PENextYear_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.Price_EPS_Estimate_Next_Year_yahoo floatValue]] compare: [NSNumber numberWithFloat: [d2.Price_EPS_Estimate_Next_Year_yahoo floatValue ]]];
}

//5日漲跌幅
NSInteger comparator_5DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent5day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent5day floatValue ]]];
} 
NSInteger comparator_5DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent5day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent5day floatValue ]]];
}
//10日漲跌幅
NSInteger comparator_10DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent10day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent10day floatValue ]]];
} 
NSInteger comparator_10DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent10day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent10day floatValue ]]];
}
//20日漲跌幅
NSInteger comparator_20DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent20day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent20day floatValue ]]];
} 
NSInteger comparator_20DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent20day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent20day floatValue ]]];
}
//60日漲跌幅
NSInteger comparator_60DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent60day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent60day floatValue ]]];
} 
NSInteger comparator_60DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent60day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent60day floatValue ]]];
}
//120日漲跌幅
NSInteger comparator_120DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent120day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent120day floatValue ]]];
} 
NSInteger comparator_120DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent120day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent120day floatValue ]]];
}
//240日漲跌幅
NSInteger comparator_240DayChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercent240day floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercent240day floatValue ]]];
} 
NSInteger comparator_240DayChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercent240day floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercent240day floatValue ]]];
}

//週漲跌幅
NSInteger comparator_WeekChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercentWeek floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercentWeek floatValue ]]];
} 
NSInteger comparator_WeekChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercentWeek floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercentWeek floatValue ]]];
}
//月漲跌幅
NSInteger comparator_MonthChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercentMonth floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercentMonth floatValue ]]];
} 
NSInteger comparator_MonthChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercentMonth floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercentMonth floatValue ]]];
}
//季漲跌幅
NSInteger comparator_QuarterChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercentQuarter floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercentQuarter floatValue ]]];
} 
NSInteger comparator_QuarterChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercentQuarter floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercentQuarter floatValue ]]];
}
//年漲跌幅
NSInteger comparator_YearChange_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.ChangePercentYear floatValue]] compare: [NSNumber numberWithFloat: [d1.ChangePercentYear floatValue ]]];
} 
NSInteger comparator_YearChange_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.ChangePercentYear floatValue]] compare: [NSNumber numberWithFloat: [d2.ChangePercentYear floatValue ]]];
}

//LF_Signal1
NSInteger comparator_LF_Signal1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.cLF_b1 floatValue]] compare: [NSNumber numberWithFloat: [d1.cLF_b1 floatValue ]]];
} 
NSInteger comparator_LF_Signal1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.cLF_b1 floatValue]] compare: [NSNumber numberWithFloat: [d2.cLF_b1 floatValue ]]];
}

//LF_BreakP1
NSInteger comparator_LF_BreakP1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_BreakP1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_BreakP1 floatValue ]]];
} 
NSInteger comparator_LF_BreakP1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_BreakP1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_BreakP1 floatValue ]]];
}

//LF_Signal2
NSInteger comparator_LF_Signal2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.cLF_b2 floatValue]] compare: [NSNumber numberWithFloat: [d1.cLF_b2 floatValue ]]];
} 
NSInteger comparator_LF_Signal2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.cLF_b2 floatValue]] compare: [NSNumber numberWithFloat: [d2.cLF_b2 floatValue ]]];
}

//LF_BreakP2
NSInteger comparator_LF_BreakP2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_BreakP2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_BreakP2 floatValue ]]];
} 
NSInteger comparator_LF_BreakP2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_BreakP2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_BreakP2 floatValue ]]];
}

//LF_Signal3
NSInteger comparator_LF_Signal3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.cLF_b3 floatValue]] compare: [NSNumber numberWithFloat: [d1.cLF_b3 floatValue ]]];
} 
NSInteger comparator_LF_Signal3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.cLF_b3 floatValue]] compare: [NSNumber numberWithFloat: [d2.cLF_b3 floatValue ]]];
}

//LF_BreakP3
NSInteger comparator_LF_BreakP3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_BreakP3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_BreakP3 floatValue ]]];
} 
NSInteger comparator_LF_BreakP3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_BreakP3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_BreakP3 floatValue ]]];
}

//LF_LongDay1
NSInteger comparator_LF_LongDay1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongDay1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongDay1 floatValue ]]];
} 
NSInteger comparator_LF_LongDay1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongDay1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongDay1 floatValue ]]];
}
//LF_LongDay2
NSInteger comparator_LF_LongDay2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongDay2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongDay2 floatValue ]]];
} 
NSInteger comparator_LF_LongDay2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongDay2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongDay2 floatValue ]]];
}
//LF_LongDay3
NSInteger comparator_LF_LongDay3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongDay3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongDay3 floatValue ]]];
} 
NSInteger comparator_LF_LongDay3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongDay3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongDay3 floatValue ]]];
}

//LF_ShortgDay1
NSInteger comparator_LF_ShortgDay1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgDay1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgDay1 floatValue ]]];
} 
NSInteger comparator_LF_ShortgDay1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgDay1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgDay1 floatValue ]]];
}

//LF_ShortgDay2
NSInteger comparator_LF_ShortgDay2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgDay2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgDay2 floatValue ]]];
} 
NSInteger comparator_LF_ShortgDay2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgDay2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgDay2 floatValue ]]];
}
//LF_ShortgDay3
NSInteger comparator_LF_ShortgDay3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgDay3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgDay3 floatValue ]]];
} 
NSInteger comparator_LF_ShortgDay3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgDay3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgDay3 floatValue ]]];
}

//LF_LongProfit1
NSInteger comparator_LF_LongProfit1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongProfit1 floatValue ]]];
} 
NSInteger comparator_LF_LongProfit1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongProfit1 floatValue ]]];
}
//LF_LongProfit2
NSInteger comparator_LF_LongProfit2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongProfit2 floatValue ]]];
} 
NSInteger comparator_LF_LongProfit2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongProfit2 floatValue ]]];
}

//LF_LongProfit3
NSInteger comparator_LF_LongProfit3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_LongProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_LongProfit3 floatValue ]]];
} 
NSInteger comparator_LF_LongProfit3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_LongProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_LongProfit3 floatValue ]]];
}
//LF_ShortgProfit1
NSInteger comparator_LF_ShortgProfit1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgProfit1 floatValue ]]];
} 
NSInteger comparator_LF_ShortgProfit1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgProfit1 floatValue ]]];
}
//LF_ShortgProfit2
NSInteger comparator_LF_ShortgProfit2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgProfit2 floatValue ]]];
} 
NSInteger comparator_LF_ShortgProfit2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgProfit2 floatValue ]]];
}
//LF_ShortgProfit3
NSInteger comparator_LF_ShortgProfit3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_ShortgProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_ShortgProfit3 floatValue ]]];
} 
NSInteger comparator_LF_ShortgProfit3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_ShortgProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_ShortgProfit3 floatValue ]]];
}

//MESA_FAMA1
NSInteger comparator_MESA_FAMA1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_FAMA1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_FAMA1 floatValue ]]];
} 
NSInteger comparator_MESA_FAMA1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_FAMA1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_FAMA1 floatValue ]]];
}
//MESA_FAMA2
NSInteger comparator_MESA_FAMA2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_FAMA2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_FAMA2 floatValue ]]];
} 
NSInteger comparator_MESA_FAMA2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_FAMA2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_FAMA2 floatValue ]]];
}
//MESA_FAMA3
NSInteger comparator_MESA_FAMA3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_FAMA3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_FAMA3 floatValue ]]];
} 
NSInteger comparator_MESA_FAMA3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_FAMA3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_FAMA3 floatValue ]]];
}
//MESA_MAMA1
NSInteger comparator_MESA_MAMA1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_MAMA1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_MAMA1 floatValue ]]];
} 
NSInteger comparator_MESA_MAMA1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_MAMA1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_MAMA1 floatValue ]]];
}

//MESA_MAMA2
NSInteger comparator_MESA_MAMA2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_MAMA2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_MAMA2 floatValue ]]];
} 
NSInteger comparator_MESA_MAMA2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_MAMA2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_MAMA2 floatValue ]]];
}
//MESA_MAMA3
NSInteger comparator_MESA_MAMA3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_MAMA3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_MAMA3 floatValue ]]];
} 
NSInteger comparator_MESA_MAMA3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_MAMA3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_MAMA3 floatValue ]]];
}
 
//MESA_Signal1
NSInteger comparator_MESA_Signal1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_Signal1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_Signal1 floatValue ]]];
} 
NSInteger comparator_MESA_Signal1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_Signal1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_Signal1 floatValue ]]];
}
//MESA_Signal2
NSInteger comparator_MESA_Signal2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_Signal2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_Signal2 floatValue ]]];
} 
NSInteger comparator_MESA_Signal2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_Signal2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_Signal2 floatValue ]]];
}
//MESA_Signal3
NSInteger comparator_MESA_Signal3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_Signal3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_Signal3 floatValue ]]];
} 
NSInteger comparator_MESA_Signal3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_Signal3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_Signal3 floatValue ]]];
}
//MESA_Action1
NSInteger comparator_MESA_Action1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_bs1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_bs1 floatValue ]]];
} 
NSInteger comparator_MESA_Action1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_bs1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_bs1 floatValue ]]];
}
//MESA_Action2
NSInteger comparator_MESA_Action2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_bs2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_bs2 floatValue ]]];
} 
NSInteger comparator_MESA_Action2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_bs2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_bs2 floatValue ]]];
}
//MESA_Action3
NSInteger comparator_MESA_Action3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_bs3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_bs3 floatValue ]]];
} 
NSInteger comparator_MESA_Action3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_bs3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_bs3 floatValue ]]];
}

//LF_Action1
NSInteger comparator_LF_Action1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_Action1 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_Action1 floatValue ]]];
} 
NSInteger comparator_LF_Action1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_Action1 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_Action1 floatValue ]]];
}
//LF_Action2
NSInteger comparator_LF_Action2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_Action2 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_Action2 floatValue ]]];
} 
NSInteger comparator_LF_Action2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_Action2 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_Action2 floatValue ]]];
}
//LF_Action3
NSInteger comparator_LF_Action3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.LF_Action3 floatValue]] compare: [NSNumber numberWithFloat: [d1.LF_Action3 floatValue ]]];
} 
NSInteger comparator_LF_Action3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.LF_Action3 floatValue]] compare: [NSNumber numberWithFloat: [d2.LF_Action3 floatValue ]]];
}



 
//MESA
NSInteger comparator_MESA_LongDay1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongDay1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongDay1 floatValue ]]];
} 
NSInteger comparator_MESA_LongDay1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongDay1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongDay1 floatValue ]]];
}
//MESA_LongDay2
NSInteger comparator_MESA_LongDay2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongDay2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongDay2 floatValue ]]];
} 
NSInteger comparator_MESA_LongDay2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongDay2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongDay2 floatValue ]]];
}
//MESA_LongDay3
NSInteger comparator_MESA_LongDay3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongDay3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongDay3 floatValue ]]];
} 
NSInteger comparator_MESA_LongDay3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongDay3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongDay3 floatValue ]]];
}

//MESA_ShortgDay1
NSInteger comparator_MESA_ShortgDay1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgDay1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgDay1 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgDay1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgDay1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgDay1 floatValue ]]];
}

//MESA_ShortgDay2
NSInteger comparator_MESA_ShortgDay2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgDay2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgDay2 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgDay2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgDay2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgDay2 floatValue ]]];
}
//MESA_ShortgDay3
NSInteger comparator_MESA_ShortgDay3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgDay3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgDay3 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgDay3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgDay3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgDay3 floatValue ]]];
}

//MESA_LongProfit1
NSInteger comparator_MESA_LongProfit1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongProfit1 floatValue ]]];
} 
NSInteger comparator_MESA_LongProfit1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongProfit1 floatValue ]]];
}
//MESA_LongProfit2
NSInteger comparator_MESA_LongProfit2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongProfit2 floatValue ]]];
} 
NSInteger comparator_MESA_LongProfit2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongProfit2 floatValue ]]];
}

//MESA_LongProfit3
NSInteger comparator_MESA_LongProfit3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_LongProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_LongProfit3 floatValue ]]];
} 
NSInteger comparator_MESA_LongProfit3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_LongProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_LongProfit3 floatValue ]]];
}
//MESA_ShortgProfit1
NSInteger comparator_MESA_ShortgProfit1_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgProfit1 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgProfit1_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgProfit1 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgProfit1 floatValue ]]];
}
//MESA_ShortgProfit2
NSInteger comparator_MESA_ShortgProfit2_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgProfit2 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgProfit2_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgProfit2 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgProfit2 floatValue ]]];
}
//MESA_ShortgProfit3
NSInteger comparator_MESA_ShortgProfit3_UP( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d2.MESA_ShortgProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d1.MESA_ShortgProfit3 floatValue ]]];
} 
NSInteger comparator_MESA_ShortgProfit3_DOWN( DataObject *d1, DataObject *d2, void *context ){
	return [ [NSNumber numberWithFloat: [d1.MESA_ShortgProfit3 floatValue]] compare: [NSNumber numberWithFloat: [d2.MESA_ShortgProfit3 floatValue ]]];
}
 
@end

